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

Why is the Humanoid.Died Event Not Firing on my Custom Character? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

So I'm trying to make it so that when the player dies, they respawn:

local function CharacterLoop(Player)
    Player:LoadCharacter()
    local Character = Player.Character

    local NewCharacter = game:GetService("ServerStorage"):WaitForChild("Clak"):Clone()
    NewCharacter.Parent = game.Workspace
    NewCharacter.Name = Player.Name
    Player.Character = NewCharacter

    local CameraFixer = script.CameraFixer:Clone()
    CameraFixer.Disabled = false
    CameraFixer.Parent = Player:WaitForChild("PlayerGui")

    local Humanoid = Character:WaitForChild("Humanoid") 

    NewCharacter:WaitForChild("Animate").Disabled = false

    Humanoid.Died:connect(function(deadPlayer)
        wait(2)
        CharacterLoop(Player)
    end)
end

However, the Died event does not fire at all. The Clak contains a HumanoidRootPart, a Head, and a Torso, and all of its parts are welded.

EDIT: If it helps, the model does not break apart upon death.

2 answers

Log in to vote
0
Answered by 6 years ago

You formed the function the wrong way, I am doing this on my phone so u may need to debug it a little bit, looks good so far thought.

local Player = game.Players.LocalPlayer
Player.CharacterAdded:connect(function(Character)
        Character:WaitForChild("Humanoid").Died:connect(function()
             local NewCharacter = game:GetService("ServerStorage"):WaitForChild("Clak"):Clone()
NewCharacter.Parent = game.Workspace
NewCharacter.Name = Player.Name
Player.Character = NewCharacter

local CameraFixer = script.CameraFixer:Clone()
CameraFixer.Disabled = false
CameraFixer.Parent = Player:WaitForChild(“PlayerGui”)

NewCharacter:WaitForChild("Animate").Disabled = false
        end)
    end)

Also may need to make spacing look nicer

0
It didn't work when i ordered it that way either. pi3dot14 0 — 6y
0
What line was the error SilentGalaxZy 53 — 6y
0
There was no error, it just didn't fire. pi3dot14 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I figured it out, the humanoid was the humanoid of the previous character. Using newcharacter's humanoid fixed it.

Answer this question