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

My Death Script won't work when I set it below 1?

Asked by 7 years ago

Hello everyone, I have a problem with a simple script that I made. Basically, if your health is below 1, it will play an animation, then reload the character. I tried to change the humanoid in game below 1, but nothing happens. Thank you for your help.

local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid = char.Humanoid

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://01360428041"
local track = humanoid:LoadAnimation(animation)

if humanoid.Health < 1 then
    humanoid.WalkSpeed = 0
    track:Play()
    wait(5)
    plr:LoadCharacter()
end
0
below 1 is 0 so somehow you would have to prevent the death from actually accuring bluehunter577 0 — 7y
0
Okay, ty Stephanie_Angela 2 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Ok so the best way to do this is actually through a function. Instead of

if humanoid.Health < 1 then
    humanoid.WalkSpeed = 0
    track:Play()
    wait(5)
    plr:LoadCharacter()
end

Use the following:

char:WaitForChild("Humanoid").Died:connect(function()
    humanoid.WalkSpeed = 0
    track:Play()
        wait(5)
        plr:LoadCharacter()
end)

However you dont need walkspeed set to 0 as the player is already dead. I am assuming you have that in there for a reason though so I left it there.

0
Thank you, but the reason why I put it to below < 1 is because when the humanoid dies, you can't animate it. Stephanie_Angela 2 — 7y
0
Ok, So your right. But what if you clone the character on death and then clone the death animation script into the cloned character. local cloned = Char:clone() . Their are ragdoll scripts that you can look at for reference that use this method. So maybe that can help you out CrazyRoblots 13 — 7y
Ad

Answer this question