Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I specify each player that comes from each group?

Asked by 9 years ago
local allyGuilds = {1136364,1214360,1137674,1170989,1138018,1138162,1138987,1137530,1139976,1136107,1136107,1136123,1147240}

game.Players.PlayerAdded:connect(function(plr)
--I dont know what to put here.
--I want it so that when the player joins it prints out what group the player is from and if there isnt a
--player from that group then it prints ("Player is not in a group")
end)

If anyone can do this, then they are awesome and ill give alot of rep!

0
If you're the owner of a group, I would like to become your ally. I command RADG (ROBLOX Attack and Defense Group) [NOT R.A.D.G., they're a copy of my group] TheArmoredReaper 173 — 9y

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

What you should do is make 'tagged indexes' for your allyGuilds table. That way you can iterate through the table with a generic for.. with an iterator function of pairs. This way, your first variable tag will be the index key and the second will be the index value.

Have the tag of an index as the group name and the value the group ID, then when you iterate through the table.. say the setup is like; for i,v in pairs(allyGuilds) do then i will be the tag, or name. and v will be the value, or group ID. Compare it like so.

local allyGuilds  = {
GroupName = 1136364, --GroupName is the name of the group
GroupName = 1214360, --The number is the group ID.
GroupName = 1137674,
GroupName = 1170989,
GroupName = 1138018,
GroupName = 1138162,
GroupName = 1138987,
GroupName = 1137530,
GroupName = 1139976,
GroupName = 1136107,
GroupName = 1136107,
GroupName = 1136123,
GroupName = 1147240
}

game.Players.PlayerAdded:connect(function(plr) --When a player joins
    for i,v in pairs(allyGuilds) do --iterate through allyGuilds table
        if plr:IsInGroup(v) then --if they're in current group
            print(plr.Name.. 'is in group: '..i) --Print they're in the groupname
            break --break the loop
        end
    end
end)
Ad
Log in to vote
-1
Answered by 9 years ago

You just need a print() and the correct arguments. Let me help you with this one :

local allyGuilds = {GROUP IDs SEPARATED BY COMMAS}

game.Players.PlayerAdded:connect(function(plr)
    wait(.1)   -- Wait for the game to have a chance to get the group
    for i = 1, #allyGuilds do
        if plr:IsInGroup(allyGuild[i]) then
            print(plr.Name .. "is in group " .. allyGuilds[i])
            break
            wait(.01)
        end
    else
        print(plr.Name .. " is not a member of any group")
        break
    end
end

That SHOULD work. If it doesn't, just comment this answer and I'll fix it ;)

TheArmoredReaper

0
Is is possible to like print out the name of the group they are from? AllianceScripter 30 — 9y
1
Just giving people the answer with no explanation doesn't help anyone. Explain your answer so that they can learn. Goulstem 8144 — 9y

Answer this question