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

Game isnt choosing a random player?

So I was making a script to choose a random player, but it wasn't working.

while wait(120) do
	if game.Players:GetChildren() > 1 then
		local randomPlayer = game.Players:GetPlayers()
		[math.random(2, #game.Players:GetPlayers())]

		print(randomPlayer.Name)
	end
end

1 comment

0

You had the right intentions, but you executed it incorrectly. You want to index a random position in the array determined by ':GetPlayers()': `local RandomPlayer = Players[math.random(1, #Players)]'.

1 answer

✓ Accepted answer

Almost there!, Try this:

while wait(10) do
    if #game.Players:GetChildren() > 1 then
		local Players = game.Players:GetPlayers()

		randomPlayer = Players [math.random(1, #Players )]

        print(randomPlayer.Name)
    end
end

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