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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
Joshument 110
4 years ago

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.

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. aSpecialGuy 18 — 4y
0
Honestly, I don't know, sorry! I would appreciate if you accepted or upvoted my answer, though. Joshument 110 — 4y
0
Then i have to ask it on another question :D Have a great day. aSpecialGuy 18 — 4y
0
Thank you! I am just trying to get my rank above contributor so any rep helps Joshument 110 — 4y
Ad

Answer this question