0

# Random Player Chosen, interval is empty error?

bloxxyz 274
7 years ago

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()
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.

0

Try using game.Players.NumPlayers instead of #plr.

0
I don't get the error anymore, but the script just stops working at that point now. Any tips? bloxxyz 274 — 7y
0

Try this:

h = Instance.new("Hint", game.Workspace)
plr = game.Players:GetChildren()
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....

0
I'm sorry, but I'm not a very advanced scripter and didn't understand this. Do I need to know what this is to make my script work..? bloxxyz 274 — 7y
0
This code will work, use this instead yours alessandro112 161 — 7y