I am wondering how I manipulate the name in the table that's created in this script.
for i,v in pairs(game.Players:GetPlayers()) do print(v) end
As you can see here, it'd print out all the players, though lets say I am trying to find Player1 and if he is in the game, then I want to remove him. How would I go about doing this? All I can figure out how to do with 'i,v in pairs() do' is print tables.
You don't have to use a for loop. Just use the FindFirstChild
method. This method searches for a child, by name, and returns that child if it exists. Otherwise it returns nil. This makes it useful when coupled with an if statement to check if something exists.
1 | if game.Players:FindFirstChild( "Player1" ) then |
2 | game.Players.Player 1 :Kick() |
3 | end |
I do not know how to use i,v in pairs, but this is my idea:
1 | local a = game.Players:GetChildren() |
2 |
3 | for i = 1 ,# do |
4 | print (a [ i ] .Name) |
5 | a [ i ] :Destroy() |
6 | end |