Dash Animation doesn't play

  1. What do you want to achieve?
    I want to make a dash system where if you press Q + one of the movement keys (WASD) the player will dash towards that direction.

  2. What is the issue?
    I think I’ve got the logic down however I am not being able to play any animation. I believe it is script related since I’ve tried using default animations for testing, but nothing seems to work.

  3. What solutions have you tried so far?
    I looked at some devforum posts but the one’s I’ve found don’t seem to have a concrete solution.

Script below:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local remote = ReplicatedStorage.Remotes.Dash
local animations = ReplicatedStorage.Anims.Movement.Dash

local Players = game.Players.LocalPlayer
local Character = Players.Character or Players.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")

local debounce = false

UIS.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.KeyCode == Enum.KeyCode.Q and not debounce then
		debounce = true
		
		local anim = nil
		local direction = Vector3.new(0, 0, 0)
		local wPressed = UIS:IsKeyDown(Enum.KeyCode.W)
		local aPressed = UIS:IsKeyDown(Enum.KeyCode.A)
		local sPressed = UIS:IsKeyDown(Enum.KeyCode.S)
		local dPressed = UIS:IsKeyDown(Enum.KeyCode.D)
		
		if wPressed then
			anim = animations.Front
			if aPressed then
				direction = Vector3.new(-1, 0,  1)
			elseif dPressed then
				direction = Vector3.new(1, 0, 1)
				else
				direction = Vector3.new(0, 0, 1)
			end
			
		elseif sPressed then
			anim = animations.Back
			if aPressed then
				direction = Vector3.new(-1 , 0, -1)
			elseif dPressed then 
				direction = Vector3.new(1, 0, -1)
			else
				direction = Vector3.new(0, 0, -1)
			end

		elseif aPressed then
			direction = Vector3.new(-1, 0, 0)
			anim = animations.Left
		elseif dPressed then
			direction = Vector3.new(1, 0, 0)
			anim = animations.Right
		end
		
		if direction.Magnitude > 0 then
			remote:FireServer()
		end
		
		if anim then
			Humanoid.Animator:LoadAnimation(anim)
		end

		debounce = false
	end
end)

This is my first post here, so if I made any mistakes or if you have suggestions, please let me know.
Thank you!

1 Like

You forgot to play the animation

if anim then
local humAnim = Humanoid.Animator:LoadAnimation(anim)
humAnim:Play()
end
1 Like

Thank you for the fast reply!
I have no idea how I didn’t notice that, however it only works with the default roblox dance, when I try to use my custom one, nothing plays. Do you have any suggestions on how I should to fix this issue?

Is there any errors? Maybe it’s because the rig that you’re animating with, isn’t the same as the type of rig you have while playing in-game.

It’s also probably because the animation type isn’t a “higher level” than the current playing animation. What I mean by that is that there’s a few animation types. “Core” Being the lowest, and “Action” being the highest. The highest level always takes over animations with levels lower than it. If 2 animations are playing with the same animation type, then both will fight over it.

Maybe I haven’t written in a very understandable way, but feel free to ask any questions.

Sorry for the late reply!
The output did not show any errors. About the priority level, I remeber reading somewhere (correct me if I am wrong) that moon animator automatically sets the priority of the animations to action, but I am not sure.
I made some changes to the script and now I am able to play custom animations, however I want the animation to fully play in the time span of the dash duration, if that makes sense.

Edited script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local remote = ReplicatedStorage.Remotes.Dash
local animations = ReplicatedStorage.Anims.Movement.Dash

local Players = game.Players.LocalPlayer
local Character = Players.Character or Players.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")

local debounce = false


UIS.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.KeyCode == Enum.KeyCode.Q and not debounce then
		debounce = true
		
		local anim = nil
		local direction = Vector3.new(0, 0, 0)
		local inputDirection = "look_vector"
		local unit =  0
		
		local wPressed = UIS:IsKeyDown(Enum.KeyCode.W)
		local aPressed = UIS:IsKeyDown(Enum.KeyCode.A)
		local sPressed = UIS:IsKeyDown(Enum.KeyCode.S)
		local dPressed = UIS:IsKeyDown(Enum.KeyCode.D)
		
		if wPressed then
			anim = animations.Front
			if aPressed then
				direction = Vector3.new(-1, 0,  1)
				unit = 50
			elseif dPressed then
				direction = Vector3.new(1, 0, 1)
				unit = 50
				else
				direction = Vector3.new(0, 0, 1)
				unit = 50
			end
			inputDirection = "look_vector"
			
		elseif sPressed then
			anim = animations.Back
			if aPressed then
				direction = Vector3.new(-1 , 0, -1)
				unit = -50
			elseif dPressed then 
				direction = Vector3.new(1, 0, -1)
				unit = -50
			else
				direction = Vector3.new(0, 0, -1)
				unit = -50
			end
			inputDirection = "look_vector"

		elseif aPressed then
			direction = Vector3.new(-1, 0, 0)
			unit = -50
			inputDirection = "right_vector"
			anim = animations.Left
		elseif dPressed then
			direction = Vector3.new(1, 0, 0)
			unit = 50
			inputDirection = "right_vector"
			anim = animations.Right
		end
		
		if direction.Magnitude > 0 then
			remote:FireServer(unit, inputDirection)
		end
		
		if anim then
			local humAnim = Humanoid.Animator:LoadAnimation(anim)
			humAnim:Play()
		end

		debounce = false
	end
end)

It’s very simple. Just add humAnim.Stopped:Wait() after playing humAnim to wait for it to finish.

1 Like

It works!
Thanks for all the replies and have a wonderful day.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.