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
5 years ago
Edited 5 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.

01local UIS = game:GetService('UserInputService')
02local replicatedStorage = game:GetService('ReplicatedStorage')
03local backDashEvent = replicatedStorage:WaitForChild('DashEvents').BackDashEvent
04 
05 
06local player = game.Players.LocalPlayer
07local char = player.Character
08local hum = char:WaitForChild('Humanoid')
09local root = char:WaitForChild('HumanoidRootPart')
10 
11 
12local animation = Instance.new('Animation')
13animation.AnimationId = 'rbxassetid://04793471389'
14local load = hum:LoadAnimation(animation)
15 
View all 37 lines...

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 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

you're right you do need a debounce

01local UIS = game:GetService('UserInputService')
02local replicatedStorage = game:GetService('ReplicatedStorage')
03local backDashEvent = replicatedStorage:WaitForChild('DashEvents').BackDashEvent
04 
05 
06local player = game.Players.LocalPlayer
07local char = player.Character
08local hum = char:WaitForChild('Humanoid')
09local root = char:WaitForChild('HumanoidRootPart')
10 
11 
12local animation = Instance.new('Animation')
13animation.AnimationId = 'rbxassetid://04793471389'
14local load = hum:LoadAnimation(animation)
15 
View all 42 lines...

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

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

I think this will work:

01local animTrack = load:GetPlayingAnimationTracks ( ) --we need AnimationTracks because it has Stopped event
02 
03UIS.InputBegan:Connect(function(input,gameProcessed)
04    if input.KeyCode == Enum.KeyCode.S and check and not gameProcessed then
05        if animTrack.Stopped then --check the AnimationTracks is stopped or not
06            animTrack:Play()
07        end
08 
09        backDashEvent:FireServer(root)
10        check = false
11    end
12end)

AnimationTrack

Answer this question