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
local PlayerTable = game.Players:GetPlayers() local ChosenPlayer = PlayerTable[math.random(1,#PlayerTable)] local m = Instance.new ("Message") while true do wait(10) m.Parent = game.Workspace m.Text = "The player that has been chosen is:"..ChosenPlayer"Congratulations!" wait (4) m:remove() end
Thank you.
while true do m = Instance.new ("Message")--moved this down here so we get a new message everytime. wait(10) PlayerTable = game.Players:GetChildren()--moved this so it gets a new table instead of using the old one. ChosenPlayer = PlayerTable[math.random(1,#PlayerTable)]--I moved this down here so it chooses a new random player everytime instead of once. m.Parent = game.Workspace m.Text = "The player that has been chosen is: "..ChosenPlayer.Name..", Congratulations!"--Changed this up a bit. wait (4) m:Destroy()--Changed this to destroy because it works better, or so they say. end
Well there you go. :)