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

How can i make this dash script work the way i want?

Asked by
Sorukan 240 Moderation Voter
4 years ago
Edited 4 years ago

I'm trying to make a script that makes the character model dash backwards when i double tap S. I managed to make the double tap part work but the problem is that the dash animation replays every single time i double tap S.

local UIS = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local backDashEvent = replicatedStorage:WaitForChild('DashEvents').BackDashEvent


local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild('Humanoid')
local root = char:WaitForChild('HumanoidRootPart')


local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://04793471389'
local load = hum:LoadAnimation(animation)


local check = false


UIS.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.S and not check and not gameProcessed then
        check = true
        wait(0.2)
        check = false
    end
end)


UIS.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.S and check and not gameProcessed then

        load:Play()    <----- the animation replays every time i double tap S
        backDashEvent:FireServer(root)

        check = false
    end
end)

Line 32 i believe is where the problem is. I understand that i need some sort of debounce to put a cooldown on the animation but i'm not sure where i can insert it.

0
You can use animation.Stopped, then animation:Stop() I think. matiss112233 258 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

you're right you do need a debounce

local UIS = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local backDashEvent = replicatedStorage:WaitForChild('DashEvents').BackDashEvent


local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild('Humanoid')
local root = char:WaitForChild('HumanoidRootPart')


local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://04793471389'
local load = hum:LoadAnimation(animation)


local check = false
local db = true--debounce
local cooldown = 5 - cooldown for debounce


UIS.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.S and not check and not gameProcessed and db then
        check = true
        wait(0.2)
        check = false
    end
end)


UIS.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.S and check and not gameProcessed and db then

        load:Play()    <----- the animation replays every time i double tap S
        backDashEvent:FireServer(root)

        check = false
    db = false-- now you can't fire until its true
    wait(cooldown)
    db = true
    end
end)

I didn't test it out but this should be working

0
Thanks, it worked! Sorukan 240 — 4y
Ad
Log in to vote
2
Answered by 4 years ago

I think this will work:

local animTrack = load:GetPlayingAnimationTracks ( ) --we need AnimationTracks because it has Stopped event

UIS.InputBegan:Connect(function(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.S and check and not gameProcessed then
        if animTrack.Stopped then --check the AnimationTracks is stopped or not
            animTrack:Play()
        end

        backDashEvent:FireServer(root)
        check = false
    end
end)

AnimationTrack

Answer this question