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

How to insert players into different tables based on their tag?

Asked by 3 years ago
Edited 3 years ago

In my game, I have two groups that a person can be in: players and watchers. In order to determine who is a player and who is a watcher, each player gets an overhead GUI placed in their head brick as a sort of tag which says either player or watcher. I was wondering how to place people into either a player table or a watcher table based on their tag in order to keep track of who is in each group in case they switch groups later on in the game. I'm new to scripting and I'm not sure how to go about this. I still have a lot to learn. Thank you in advance for your help. It's greatly appreciated.

Edit - I have made a player list GUI in starter GUI but I can't figure out how to put only the players with the player tag into the list and not the ones with the watcher tag.

0
Do you want me to give you a script that gives the role of a group and the username on top of their character in game? iivSnooxy 248 — 3y
0
I want the people in the watchers group to click a button and be able to see a list of the people in the players group. Then they can click a player from the list and vote for what challenge that player will do in the next round. Icecube_376 9 — 3y
0
So have you done any scripting or any other language before? SteamG00B 1633 — 3y
0
No I haven't Icecube_376 9 — 3y

1 answer

Log in to vote
0
Answered by
sngnn 274 Moderation Voter
3 years ago

First, loop through the players.

for i,p in pairs(game.Players:GetChildren()) do --looppppp

After, you'd need to use whatever way you have to get their role.

for i,p in pairs(game.Players:GetChildren()) do --looppppp
    local role = p.RoleThingy

Then, place them in one of two tables using table.insert based on their role. You could, however, just use a table inside of another...

local roles = {}
for i,p in pairs(game.Players:GetChildren()) do --looppppp
    local role = p.RoleThingy
    table.insert(roles,{p=role.Role})
end
Ad

Answer this question