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

player is a nill value?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question