Animation STILL plays after cooldown

  1. What do you want to achieve? Keep it simple and clear!
    The animation does not play when theres a 3 second cooldown.

  2. What is the issue? Include screenshots / videos if possible!
    The animation plays when theres a cooldown.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried making a topic, multiple web searches, and does not ever get close to fixing my problem.


local UIS = game:GetService("UserInputService")
local char = script.Parent
local playAnim

local keybind = Enum.KeyCode.E
local canslide = true
local debounce = 3

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end

	if input.KeyCode == keybind and canslide then
		local slideAnim = Instance.new("Animation")
		slideAnim.AnimationId = "rbxassetid://9157679954"
		canslide = false

			playAnim = char.Humanoid:LoadAnimation(slideAnim)
			playAnim.Priority = Enum.AnimationPriority.Action2
			playAnim:Play()


		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
		slide.Parent = char.HumanoidRootPart

		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(debounce)
		canslide = true
	end
end)
3 Likes

This should work as intended, I don’t see the problem.

Edit: I can try writing something similar but it’s up to you

Instead of loading the animation through humanoid, consider using the Animator

1 Like

How can this work with this script

Animator should be a child of Humanoid, you can run the game and see it for yourself in the explorer

so…

local animator = humanoid:FindFirstChildOfClass("Animator")

?

That’s correct. Consider using the Animator docs I linked you.

Ok but one question.

I saw the example in that docs you sent, what does animationtrack return, and is it important here?

return animationTrack

Animation Track is created when you call the Load method on the animator. They’re simply returning it to have access to it somewhere else.

1 Like

Probably dumb but, I can’t dash (Velocity not changing )and nothing changed, It’s still running in cooldown

-- Put "Slide Ability" in StarterPlayer and StarterCharacterScripts
--                        Enjoy This Ability

local UIS = game:GetService("UserInputService")
local char = script.Parent
local humanoid = char:FindFirstChildOfClass("Humanoid")

local keybind = Enum.KeyCode.E
local canslide = true
local debounce = 3

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end

	if input.KeyCode == keybind and canslide then
		local animator = humanoid:FindFirstChildOfClass("Animator")
		animator.AnimationId = "rbxassetid://9157679954"
		canslide = false

			local playAnim = humanoid:LoadAnimation(animator)
		playAnim:Play()


		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
		slide.Parent = char.HumanoidRootPart

		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(debounce)
		canslide = true
	end
end)

That’s not how you load an animation using the animator. Take a look closely at the example provided in the docs. You have to use the LoadAnimation method on the Animator not the Humanoid.

			local playAnim = animator:LoadAnimation(animator)
		playAnim:Play()

Exact same error!
I can’t dash (velocity,) and it still moves when cooldown???
I am genuinely confused right now


Actually wait

1 Like

You tried to index AnimationID to Animator. Try this:

-- Put "Slide Ability" in StarterPlayer and StarterCharacterScripts
--                        Enjoy This Ability

local UIS = game:GetService("UserInputService")
local char = script.Parent
local humanoid = char:FindFirstChildOfClass("Humanoid")

local keybind = Enum.KeyCode.E
local canslide = true
local debounce = 3

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end

	if input.KeyCode == keybind and canslide then
		local animator = humanoid:FindFirstChildOfClass("Animator")
		local animation = Instance.new("Animation")
		animation.AnimationId = "rbxassetid://9157679954"
		canslide = false

		local playAnim = animator:LoadAnimation(animator)
		playAnim:Play()


		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
		slide.Parent = char.HumanoidRootPart

		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(debounce)
		canslide = true
	end
end)
1 Like

image
shouldn’t the two () thing have (animation) instead of animator?

1 Like

yes forgot that add it. thirtyness char

1 Like

TRUE

TRUE TRUE

blah blah thirtness char

1 Like

OK i can dash, the dash velocity has a cooldown BUT its back to square one.

the animation still plays in cooldown

Set the priority of the animation to “Movement”

1 Like