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 10 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

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.

1 answer

Log in to vote
0
Answered by
ultrabug 306 Moderation Voter
10 years ago
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. :)

Ad

Answer this question