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

This Double Jump Script Is Working, But I Want To Play A Animation, How Do I Do this?

Asked by 3 years ago

when i do the normal humanoid:LoadAnimation(animation) script line it said LoadAnimation() is not valid member of humanoid code down below

local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character
local humanoid

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxasset://6256599198"

local FlipAnim = humanoid:LoadAnimation(Animation)

local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local Time = 0.2
local multiplier = 2

function onJumpRequest()

    if not character or not humanoid or not character:IsDescendantOf(workspace)
        or humanoid:GetState() == Enum.HumanoidStateType.Dead then
        return
    end
    if canDoubleJump and not hasDoubleJumped then
        hasDoubleJumped = true
        humanoid.JumpPower = oldPower * multiplier
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
        FlipAnim:Play()
        wait()
    end
end

local function characterAdded(newCharacter)
    character = newCharacter
    humanoid = newCharacter:WaitForChild("Humanoid")
    hasDoubleJumped = false
    canDoubleJump = false
    oldPower = humanoid.JumpPower
    humanoid.StateChanged:Connect(function(old, new)
        if new == Enum.HumanoidStateType.Landed then
            if hasDoubleJumped == true then
                script.Sound:Play()
            end
            canDoubleJump = false
            hasDoubleJumped = false
            humanoid.JumpPower = oldPower
            wait()
        elseif new == Enum.HumanoidStateType.Freefall then
            wait(Time)
            canDoubleJump = true
        end
    end)
end
if player.Character then
    characterAdded(player.Character)
end

player.CharacterAdded:Connect(characterAdded)
userInputService.JumpRequest:Connect(onJumpRequest)

Answer this question