Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i stop the walk animation and play the attack animation?

I Just did a script like this but when i walk and click mouse button, i want to stop the walk animation and play the sword animation and when its finished, i want to play walk and stop sword. How can i do this?

local CanAttack = true

local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")


script.Parent.Equipped:Connect(function()

local idle = Humanoid:LoadAnimation(script.Idle)
local walk = Humanoid:LoadAnimation(script.Walk)

Humanoid.Running:Connect(function(speed)
	
	if speed > 0 then
		idle:Stop()
		walk:Play()

	elseif speed == 0 then
		idle:Play()
		walk:Stop()
	end
	
end)
	
end)


script.Parent.Activated:Connect(function()

local clone = game.Workspace.Anims.KatanaAttack:Clone()
clone.Parent = script.Parent.anims
game.Workspace.Anims.KatanaAttack:Destroy()
local attack = player.Character.Humanoid:LoadAnimation(script.KatanaAttack)

if CanAttack == true then
	
	attack:Play()
	clone.Parent = script.Parent
	wait(1)
	attack:Stop()
	clone.Parent = game.Workspace.Anims
	
end
wait(1)
end)

1 answer

✓ Accepted answer

What you want to do here is change the priority of the animation. You can change this in the animation editor. There are 4 different priorities:

Core - Lowest Priority, all animations in this will not be played over the others. Roblox animations are this priority

Action - Second Lowest. Will play over Core, but not anything else

Movement - Second Highest, plays over Action and Core, but not Idle.

Idle - Highest Priority. Will play over any other animation.

To change these, go to your animation editor. Load in your animations with the import tool, and go to settings > priority > movement. You don’t want this to be Idle as that would cause it to play over your idle animation.

Actions are named respectfully, so the attack animation should be an ACTION, and your walk animation should be MOVEMENT. Other than that, your script looks fine to me.

4 comments

0

Yeah, everything is fixed. Thanks. But now, sometimes my walking animation broking. Can you tell me another way to active the walk animation? Any smooth way.

0

Honestly, I don't know, sorry! I would appreciate if you accepted or upvoted my answer, though.

0

Then i have to ask it on another question :D Have a great day.

0

Thank you! I am just trying to get my rank above contributor so any rep helps

This discussion is preserved as it was. New answers, comments, and votes are closed.