local plr = game.Players.LocalPlayer repeat wait(1) until plr.Character local chr = plr.Character chr.Humanoid.Died:Connect(function() print("Character died") plr.CharacterAdded:Wait() print("Character respawned") end)
This is the first code before editing
local plr = game.Players.LocalPlayer repeat wait(1) until plr.Character local chr = plr.Character chr.Humanoid.Died:Connect(function() print("Character died") plr.CharacterAdded:Wait() print("Character respawned") chr = plr.Character chr:WaitForChild("Humanoid") end)
This is the code after editing
Seems to be working right, but when player died again, function is not working in both codes. How do I detect when humanoid died from a local script properly so this function can work forever? I need this script to be located in the player scripts, not character scripts.
You should use CharacterAdded to see when the character is added again and get the updated player character:
game.Players.LocalPlayer.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() --do your thing end) end)
Sorry for improper tabbing, im on my phone.