Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

4 comments

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?

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.

0

So have you done any scripting or any other language before?

0

No I haven't

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.