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

How do I go through a table to find someone's name?

What I mean is, how would I find someone from the players section by using a table. So for example if the code takes all the names and puts them in a table, how would I use that table then to find them all?

			for _,v in pairs (game.Players:GetChildren()) do
			        table.insert(players, v.Name)
			end
			for _,v in pairs (game.Players:GetChildren()) do
				if v.Name == players then
				v.Status = "Nub"
				end
			end

3 answers

game.Players:GetPlayers() returns a table. You shouldn't use GetChildren, and you don't have to insert each table individually.

If you want to see if a player is in the game, you can use the FindFirstChild method of the Players service

you could try getting the current players like this

players = game.Player:GetChildren()

for key, name in pairs(players) do
print(key, name)
end

You're close, except there's 3 things you need.

  1. You don't need lines 1-3. game.Players:GetChildren () is the only table you need.
  2. You can rename v to anything (best to name it player, so you can see what's going on better)
  3. I'm not sure Status is a property of Player.

Here's a revision:

for _,player in pairs (game.Players:GetChildren()) do
    if v.Name == player.Name then -- needed the .Name after player because otherwise you're comparing a name to an object
    v.Status = "Nub" -- okay...?
    end
end

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