I'm having a lot of trouble with a script in my game:
game.Players.PlayerAdded:connect(function(player) wait(1) game.ReplicatedStorage.UpdateStatus:FireAllClients() player.Character.Humanoid.Died:connect(function() print("HUMANOID DIED") local playerNum for i, plr in pairs(players:GetPlayers()) do if plr == player.Name then playerNum = i print(player.Name .. "leaving game.") end end table.remove(playersPlaying, playerNum) print(player.Name .. "leaving game.") end) end)
Can someone explain to me why the .Died event only seems to run once? To my knowledge, it should run like this: player joins, event's connected. Whenever the player dies from that point on, the code will run. Is this not the case? If so, can someone explain why? Help is much appreciated.
Basically, the character can change. Once it dies, it re-spawns a new Character. This might be the reason this is happening.
Use a CharacterAdded
event. Like so,
game.Players.PlayerAdded:connect(function(player) plr.CharacterAdded:connect(function(char) wait(1)--I would also maybe remove this game.ReplicatedStorage.UpdateStatus:FireAllClients() char.Humanoid.Died:connect(function() print("HUMANOID DIED") local playerNum for i, plr in pairs(players:GetPlayers()) do if plr == player.Name then playerNum = i print(player.Name .. "leaving game.") end end table.remove(playersPlaying, playerNum) print(player.Name .. "leaving game.") end) end) end)
I hope I helped.
Good Luck!