I’m using this function to reset all players I don’t know if saying “if player” will result in an error in an error if the player leaves the game. Is there a better solution
for index, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Team.Name == "Playing" then
local pickedIsland = RandomFunctions.PickARandomItemFromTable(game:GetService("Workspace").Spawns:GetChildren())
player.Team = game:GetService("Teams").Spectator
if player then
local NewValue = Instance.new("IntValue")
NewValue.Value = tick()
NewValue.Name = "EndTick"
NewValue.Parent = PlayerRoundData[player.Name]
player:LoadCharacter()
end
end
end
for index, player in pairs(game:GetService("Players"):GetPlayers()) do
if player.Team.Name == "Playing" then
local pickedIsland = RandomFunctions.PickARandomItemFromTable(game:GetService("Workspace").Spawns:GetChildren())
player.Team = game:GetService("Teams").Spectator
if player.Parent then
local NewValue = Instance.new("IntValue")
NewValue.Value = tick()
NewValue.Name = "EndTick"
NewValue.Parent = PlayerRoundData[player.Name]
player:LoadCharacter()
end
end
end
That’s the point of the if statement. If the player doesn’t exist then the code inside that if statement doesn’t fire. That if statement is making sure Player.Name doesn’t = nil