I have an issue with my game where if one player leaves when there is 3 or more the entire system breaks (I’ve tried adding a players.playerremoving) but it wont work for some reason. The issue is caused by still having 3 or more players in the playing table but whenever the player leaves it is unable to give them the item.
RunService.Heartbeat:Connect(function()
players.PlayerRemoving:Connect(function(leftplayer)
print("PLAYER REMOVED")
if table.find(PlayingPlayers, leftplayer) then
print("FOUND PLAYER")
table.remove(PlayingPlayers, leftplayer)
end
end)
people = players:GetPlayers()
for i, player in PlayingPlayers do
local char = player.Character
local humanoid = char.Humanoid
local humanoidRootPart = char.HumanoidRootPart
if humanoid.Health <= 0 then
table.remove(PlayingPlayers, i)
print(PlayingPlayers)
end
end
if #people < 2 then
game.ReplicatedStorage.PlayerLeft:FireAllClients(PlayingPlayers)
else
if gameActive == false then
gameActive = true
Intermission()
StartRound()
end
end
end)
this script constantly gives the error (only when someone leaves) “attempt to index nil with humanoid”