Tried making a random player chooser but doesn't work.. please help me fix this, or you could write a new script explaining the actions
players = game.Players:GetChildren() randoms = players[math.random(1,#players)] chosen = randoms.Name print(chosen)
Please help :(
I just tested out this script, and now I know whats wrong. Your script is running when there is no players on the game. Here is a script that will give you the random player, after the player has joined.
game.Players.ChildAdded:connect(function() players = game.Players:GetChildren() --Gets a table of all the players randomPlayer = players[math.random(1, #players)] --Gets a random player from the players table print(randomPlayer.Name) --Prints the name of the random player end)
I hope this helps, and if you have any questions, just comment.
-- You can take out the while wait() do loop and still have my script run correctly. :D Hope this helps you!
while wait() do local plr=game.Players:GetPlayers()[math.random(1,game.Players.NumPlayers)] print(plr.Name) wait(10) end