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

How do I get all the groups the given player is in?

Asked by
Nidoxs 190
9 years ago

Now I know that this exists : but I am confused on how I would use this. I want to make it so I can Get All The Groups the player is in then get the primary groups and do somthing with that. Here is my test code that didn't work.

function playerJoin(player)
    local a = player:GetGroupsAsync()
    print(a)
end

game.Players.PlayerAdded:connect(playerJoin)
0
Is there any error messages in Script Analysis? TheHospitalDev 1134 — 9y
0
No. @SickAtHackers Nidoxs 190 — 9y

1 answer

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
9 years ago

This article supposes GetGroupsAsync() is an existing function obtaining the player's groups

You cannot directly print tables. What you will have to do is get each item of the table and print it one-by-one. This goes for every table you want to obtain the items from.

So we use this for i=1 loop, as an example, to get them:

function playerJoin(player)
    local g = player:GetGroupsAsync()
    for i=1,#g do --I will start from 1 and increase up to the number of groups
        print(g[i]) --Each group in the table is chosen with i
    end
end

game.Players.PlayerAdded:connect(playerJoin)

There are a few other ways to get the items, but this is the most efficient way known.

0
I would use a generic for loop instead of regular. Regular for loops can get confusing at times. Scriptecx 124 — 9y
0
Again I get this : 12:49:40.127 - GetGroupsAsync is not a valid member of Player 12:49:40.128 - Script 'Workspace.Script', Line 2 12:49:40.130 - Stack End Nidoxs 190 — 9y
Ad

Answer this question