Hi, I'm not sure what the error means, and I can't quite figure it out. I asked the Scripting Helpers forum at ROBLOX.com, and I did get some help, but they couldn't help me figure it out either.
The script's objective is to choose a random player, and call out its name in a Hint. Here is the script, and this was the error:
15:37:43.914 - Workspace.Script:8: bad argument #2 to 'random' (interval is empty)
h = Instance.new("Hint", game.Workspace) plr = game.Players:GetPlayers() game.Players.PlayerAdded:connect(function(players) wait(5) h.Text = ("Welcome to Game") wait(2) h.Text = ("Choosing Ghost..") RandomPlr = plr[math.random(1, #plr)] ChosenPlr = plr[RandomPlr] wait(3) h.Text = ("The ghost is:" .. ChosenPlr) end)
*EDIT It's been around 4 days and my problem still consists. I am getting errors each time, and while some answers were helpful, this short scope will not function properly. Can I at least get some advice or tips, maybe a wiki article to prevent this, or a good solution? Anything will help. Thank you.
Try using game.Players.NumPlayers
instead of #plr
.
Try this:
h = Instance.new("Hint", game.Workspace) plr = game.Players:GetChildren() game.Players.PlayerAdded:connect(function(player) wait(5) h.Text = ("Welcome to Game") wait(2) h.Text = ("Choosing Ghost..") local randomPlayer = plr[math.random(1, #plr)] wait(3) h.Text = ("The ghost is: " .. randomPlayer) end)
By the way, why are you running a function that need to be called in the server side as client side one? You need a function that updates the server and get the current players, from that just see if there are enough player, if true then call this function on every player, otherwise wait 1 second and return the same function and check again....