while wait() do for i = 5,0,-1 do --Lobby Timer wait(sec) print(i.." / Before") end for _, player in pairs(game.Players:GetPlayers()) do --Player Monster local randomplayer = player[math.random(1, #player)] end end
The output say that player is a userdata value and i d'ont know how to fix this
well, the reason might be that player, is well... a player object and not a table so you might want to try something on the lines of this
math.randomseed(tick()) while true do local plrs = game.Players:GetPlayers() local rIndex = math.random(1,#plrs) local randomplr = plrs[rIndex] wait() end
So things to take away:
1) don't use while wait() do end, use while true do wait() end 2) use math.randomseed(tick()) for "better randomness"
If you're trying to select a random player, that's not the way to do it.
Try this:
while wait() do for i = 5,0,-1 do --Lobby Timer wait(sec) print(i.." / Before") end local players = game.Players:GetPlayers() local randomplayer = players[math.random(1, #players)] end
a for loop
literates through a table, and the variable is the object, not a table which you'd use a # operator to get a length. this means you dont need to use a for loop
to get a random player, but just use game.Players:GetPlayers()
, math.random
and the #
operator alone.
while true do for i = 5,0,-1 do --Lobby Timer wait(sec) print(i.." / Before") end local players = game.Players:GetPlayers() local chosenPlayer = players[math.random(1,#players)] print(chosenPlayer.Name) -- example -- do stuff here -- you dont need a wait as theres a for loop which yields end