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
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.
for _,plr in pairs(game.Players:GetPlayers()) do ... end