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

(AUTO-SOLVED)why does my jump combo sometimes works and sometimes it does not?

Asked by 4 years ago
Edited 4 years ago

Sorry for any English mistakes.

I'm making a plataformer that has a mechanic where you can combine jumps.

Jump + dash + double jump+dash.

The problem is that the jump combo sometimes works and sometimes it glitches. When it glitches the player jumps then dash normally,but when they double jump occurs the repeat cycle of the dash animation doesn't and making the dash animation don't cancel when double jumping and the debounce staying as false.

here's the doublejump script

local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character 
local humanoid =script.Parent:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = 'http://www.roblox.com/Asset?ID=3288217405'
local animTrack = humanoid:LoadAnimation(animation)
animTrack:AdjustSpeed(2) 
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower 
local TIME_BETWEEN_JUMPS = 0.1
local DOUBLE_JUMP_POWER_MULTIPLIER=1.5
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
    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
    print("doubleJump")
        animTrack:Play()
     humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
        hasDoubleJumped = true
        humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER 
    end
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
            canDoubleJump = false
            hasDoubleJumped = false
            humanoid.JumpPower = oldPower       
        elseif new == Enum.HumanoidStateType.Freefall then
             wait(TIME_BETWEEN_JUMPS)
             canDoubleJump = true         
        end
    end)
end

if localPlayer.Character then
    characterAdded(localPlayer.Character)
end

dash script

if input.KeyCode == Enum.KeyCode.E and humanoid:GetState() == Enum.HumanoidStateType.Freefall and debounce  then
        print"dash"
        animTrackdash:Play()
        local Root = localPlayer.character:WaitForChild("HumanoidRootPart")
        Root.Velocity = (Root.CFrame.LookVector + Root.CFrame.UpVector*0.3)*(30+humanoid.WalkSpeed*2)
        debounce = false

        repeat 
            wait() 
            animTrackdash:Play() animTrackdash.TimePosition = 0.300 
            until humanoid:GetState()== Enum.HumanoidStateType.Jumping
             or  humanoid:GetState()== Enum.HumanoidStateType.Landed
        debounce = true
        animTrackdash:Stop()

What confuses me the most is that sometimes the jump combo works fine,but sometimes it just glitches.

Answer this question