Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

humanoid.Died from local script?

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.

1 answer

✓ Accepted answer

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.

6 comments

0

You might also want to call it from a remote event.

0

I dont think calling it from a remote event is not the best idea. Are you talking about starter character script or a server script?

0

Btw this code is working how do i accept it?

0

You select it as the solution :)

0

You click “Accept Answer” below my post.

0

I can only report you, there is no button "accept answer"

This discussion is preserved as it was. New answers, comments, and votes are closed.