It shouldn't be nil, I have the variable in my script, but it will not identify. Here is the script, it's pretty short, if someone could help that would be great. The error is on line 11, I commented the error point.
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, game.Players.NumPlayers)] ChosenPlr = plr[RandomPlr] --ChosenPlr variable identified right here wait(3) h.Text = ("The ghost is:") .. ChosenPlr.Name --This line, I get "error 'ChosenPlr' nil value" ? end)
Thank you.
You're already getting the chosen player in RandomPlr by indexing the plr table. ChosenPlr is getting plr[plr[math.random(...)]]
instead of plr[math.random(...)]
RandomPlr = plr[math.random(1, game.Players.NumPlayers)] ChosenPlr = plr[RandomPlr] --ChosenPlr variable identified right here
You are getting the player and then getting it a second time using the player as the arguement.
Get rid of RandomPlr and simply do this:
ChosenPlr = plr[math.random(1, game.Players.NumPlayers)]