Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

humanoid.Died from local script?

Asked by 4 years ago
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

Log in to vote
2
Answered by
iOwn_You 543 Moderation Voter
4 years ago

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.

0
You might also want to call it from a remote event. MajenBej 5 — 4y
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? MrSuperKrut 167 — 4y
0
Btw this code is working how do i accept it? MrSuperKrut 167 — 4y
0
You select it as the solution :) iOwn_You 543 — 4y
View all comments (2 more)
0
You click “Accept Answer” below my post. iOwn_You 543 — 4y
0
I can only report you, there is no button "accept answer" MrSuperKrut 167 — 4y
Ad

Answer this question