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

Why do animation scripts in backpack not work after initial death?

This is one of my custom animations that overrides the default jump animation. It works fine, but once I reset, the animation and the double jump don't work anymore. I have a feeling that it has to do with my script still being locked to the dead Humanoid even after the character respawns, but even if this is the case, I'm not sure what I would do about it

player = game:GetService("Players").LocalPlayer 
mouse = player:GetMouse() 
c = player.Character or player.CharacterAdded:Wait() 
humanoid = c:WaitForChild("Humanoid") 
humanoid.WalkSpeed = 30


 
Flip = Instance.new("Animation") Flip.AnimationId = "rbxassetid://4378710738" canDoubleJump = true

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then c.Humanoid.JumpPower = 100 
	if c.Humanoid:GetState() == Enum.HumanoidStateType.Freefall and canDoubleJump  		
		then c.Humanoid.JumpPower = 60 		
		c.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) 
		humanoid:LoadAnimation(Flip):Play() canDoubleJump = false 
	end 
end

humanoid.StateChanged:Connect(function(old, new) 
	if new == Enum.HumanoidStateType.Landed and old == 		
	Enum.HumanoidStateType.Freefall 
		then canDoubleJump = true 
	end 
end)

1 answer

✓ Accepted answer

I found the solution. Apparently, this code below doesn't work.

player.CharacterAdded:Wait()

Instead, do

repeat wait() until game.Players.LocalPlayer.Character
character = player.Character or player.CharacterAdded:Wait()

1 comment

0

That's redundant. Just do "character = player.Character or player.CharacterAdded:Wait()" because with what you're doing currently, you're just waiting until the character spawns (which is what CharacterAdded:Wait() does, it waits for the CharacterAdded event to be fired)

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