Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Random Player Chosen, interval is empty error?

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.

3 answers

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

1 comment

0

I don't get the error anymore, but the script just stops working at that point now. Any tips?

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

2 comments

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..?

0

This code will work, use this instead yours

This discussion is preserved as it was. New answers, comments, and votes are closed.