I want it to randomly choose a Player and post a Message. Error: bad argument #2 to 'random' (number expected, got table) Thats what roblox tells me
01 | local PlayerTable = game.Players:GetPlayers() |
02 | local ChosenPlayer = PlayerTable [ math.random( 1 ,#PlayerTable) ] |
03 | local m = Instance.new ( "Message" ) |
04 |
05 | while true do |
06 | wait( 10 ) |
07 | m.Parent = game.Workspace |
08 | m.Text = "The player that has been chosen is:" ..ChosenPlayer "Congratulations!" |
09 | wait ( 4 ) |
10 |
11 | m:remove() |
12 | end |
Thank you.
01 | while true do |
02 | m = Instance.new ( "Message" ) --moved this down here so we get a new message everytime. |
03 | wait( 10 ) |
04 | PlayerTable = game.Players:GetChildren() --moved this so it gets a new table instead of using the old one. |
05 | ChosenPlayer = PlayerTable [ math.random( 1 ,#PlayerTable) ] --I moved this down here so it chooses a new random player everytime instead of once. |
06 | m.Parent = game.Workspace |
07 | m.Text = "The player that has been chosen is: " ..ChosenPlayer.Name.. ", Congratulations!" --Changed this up a bit. |
08 | wait ( 4 ) |
09 | m:Destroy() --Changed this to destroy because it works better, or so they say. |
10 | end |
Well there you go. :)