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)
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.