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

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

Asked by 4 years ago
Edited 4 years ago

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

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

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()

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) synoooot 15 — 4y
Ad

Answer this question