check if player is in group

-- Replace "PLAYER_ID" with the ID of the player you want to check
local playerId = "PLAYER_ID"

-- Replace "GROUP_ID" with the ID of the group you want to check against
local groupId = "GROUP_ID"

local groupCheckUrl = "https://api.roblox.com/users/"..playerId.."/groups"

-- Make a request to get the player's groups
local response = game:HttpGet(groupCheckUrl)

-- Parse the JSON response
local playerGroups = game:GetService("HttpService"):JSONDecode(response)

local isInGroup = false

-- Loop through the player's groups to check if they belong to the specified group
for _, group in ipairs(playerGroups) do
    if group.Id == groupId then
        isInGroup = true
        break
    end
end

-- Check the result
if isInGroup then
    print("Player is in the group")
else
    print("Player is not in the group")
end

Explanation:

  1. local playerId = "PLAYER_ID": Defines a variable playerId to hold the ID of the player you want to check. Replace "PLAYER_ID" with the actual ID of the player.

  2. local groupId = "GROUP_ID": Defines a variable groupId to hold the ID of the group you want to check against. Replace "GROUP_ID" with the actual ID of the group.

  3. local groupCheckUrl = "https://api.roblox.com/users/"..playerId.."/groups": Constructs a URL to check the groups of the specified player using their ID.

  4. local response = game:HttpGet(groupCheckUrl): Sends an HTTP GET request to the constructed URL to retrieve information about the player's groups.

  5. local playerGroups = game:GetService("HttpService"):JSONDecode(response): Parses the JSON response received from the API to obtain the player's groups.

  6. local isInGroup = false: Initializes a variable isInGroup to false to indicate that the player is not initially assumed to be in the group.

  7. for _, group in ipairs(playerGroups) do ... end: Iterates through each group the player is a member of to check if any matches the specified group ID.

  8. if group.Id == groupId then ... end: Checks if the ID of the current group in the iteration matches the specified group ID.

  9. isInGroup = true; break: Sets isInGroup to true if a match is found and breaks out of the loop.

  10. if isInGroup then ... else ... end: Checks the value of isInGroup and prints whether the player is in the specified group or not.