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

I Want To Select A Random Player And Put It In A Hint but It Is Not Working Plz Help?

Here Is My Code Plz Help

local Player = game.Players:GetChildren()
	local Random123 = math.random(1, #Player)
	local hint = Instance.new("Hint")
	hint.text = Random123.."Has Been Chosen"

this is the error

bad argument #2 to 'random' (interval is empty)

1 answer

✓ Accepted answer

What that means is that Player is an empty Table.

You should only run this code if there is at least one player in the game, and optimally if there are two or more:

while game.Players.NumPlayers < 2 do
	game.Players.PlayerAdded:wait()
end

local Player = game.Players:GetPlayers() --The prefered method for getting all Players.
local Random123 = Player[math.random(#Player)] --No need to use a `1` there, it's automatically filled, and you never actually got the specific player chosen, only their index within the table.
local hint = Instance.new("Hint", workspace) -- Gotta parent it!
hint.Text = Random123.Name .. " Has Been Chosen" --There needs to be a space before `has` or this will look weird.

2 comments

0

ok thanks

0

that helped alot

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