IsInGroup and GetRankInGroup don’t return group ID’s. This is a big problem because I have a list of groups that are listed in a dictionary and the fastest way to check if a user is in one of them is to run a for do function that tries every group id, but it doesn’t return the group id afterwards, which I actually also need.
module script
local groups = {[123456] = "Stacking Numbers", [22222] = "Only Twos"}
function module:GetGroupsID(id) -- the only working approach so far, but it still doesn't return the matching id
for id,_ in pairs(groups) do
return id
end
server script
if plr:IsInGroup(module:GetGroupsID()) then
local groupid = plr:IsInGroup(Database:GetGroupsID()) -- returns true but doesn't return id, mildly infuriating
I’ve tried using several different approaches with functions, but none of them worked. Chances are if you propose an idea it’s probably been done (unless there’s some innovative secret way that I don’t know of).
Is there actually a way to make this work without hacky workarounds, or will IsInGroup return ID’s any time soon?
local groups = {[123456] = "Stacking Numbers", [22222] = "Only Twos"}
function module:GetGroupsID(id) -- the only working approach so far, but it still doesn't return the matching id
for id,_ in pairs(groups) do
return id
end
Your code is being cut off short - the loop only runs once, then terminates because you are returning under any condition. This is part of the problem. Also refer to the reply by @ChipioIndustries.
Ight, so the function player:IsInGroup() doesn’t return an ID, as the argument (that’s what goes in these parenthesis) is the group ID, which it will return true if the player is in the given group. As @FifthInfinity stated, you’ll need to use GroupService:GetGroupsASync() to find all of the players groups, and then just perform a check there.
Otherwise, you can use a loop that cycles through all of the values in the groups table, and if the player is in one of the groups in the table it breaks the loop and returns the group id that the player is in
e.g:
local groups = {["Stacking Numbers"] = 123456, ["Only Twos"] = 22222 }
function module:GetGroupsID(player) --this is the loop function]
local groupID = false
for i, v in pairs(groups) do --the loopy bit
if player:IsInGroup(v[1]) then --as a precaution, we state the position of the value
groupID = v[1]
break
end
end
return groupID
end
And then for the server:
local groupID = GroupModule:GetGroupsID(player)
if groupID = CORRECT_GROUP_ID then
--put your code here
end
Hope that’s easy enough to understand, but what I’ve done is added a loop in the module, which checks if the player is in a group. If the player is not in a group, it returns false. Otherwise, it returns the groupID of the group that the player is in (i.e. 22222 or 123456). Then you can make a decision based on that info.