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

player is a nill value?

i have a script that will find players on a team's names but i have a error

here is my code:

for i,v in pairs(game.Teams["Players"]:GetPlayers())do
	wait(2)
	local plr = Players:GetPlayerFromCharacter(v)
	h.Text = ("The Winners are:"..plr.Name)
end

h is defined and working but whenever i run the code it says:

16:13:55.178 - Workspace.Scripts.Game Flow:69: attempt to index local 'plr' (a nil value)

i check the teams and my player is on the Players team but it still says the error

please help

1 answer

✓ Accepted answer

Problem


The reason this player is nil in this case is that the GetPlayers function already gets all the players, which are player object, so there really isn't a need to use the GetPlayerFromCharacter function, since the objects inside the GetPlayers table are players, not characters.


Solution


for _,plr in pairs(game.Players:GetPlayers()) do
	...
end

References


GetPlayers function

GetPlayerFromCharacter function

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