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

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

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

2 comments

0

below 1 is 0 so somehow you would have to prevent the death from actually accuring

0

Okay, ty

1 answer

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.

2 comments

0

Thank you, but the reason why I put it to below < 1 is because when the humanoid dies, you can't animate it.

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

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