Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.
0
ok thanks zangdragonoid 0 — 9y
0
that helped alot zangdragonoid 0 — 9y
Ad

Answer this question