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
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.