Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me with this Script?

Asked by 11 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

01local PlayerTable = game.Players:GetPlayers()
02local ChosenPlayer = PlayerTable[math.random(1,#PlayerTable)]
03local m = Instance.new ("Message")
04 
05while true do
06    wait(10)
07    m.Parent = game.Workspace
08m.Text = "The player that has been chosen is:"..ChosenPlayer"Congratulations!"
09wait (4)
10 
11m:remove()
12end

Thank you.

1 answer

Log in to vote
0
Answered by
ultrabug 306 Moderation Voter
11 years ago
01while 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.
10end

Well there you go. :)

Ad

Answer this question