Animation tool help needed

I made a script that plays a walking animation when equipped, but I want an idle animation but I don’t know how to do this. Please help

local playing = false
local tool = script.Parent
local anim = Instance.new(“Animation”)
anim.AnimationId = “http://www.roblox.com/Asset?ID=15902786962
local track

tool.Equipped:Connect(function()
if playing == false then
playing = true
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
end
end)

tool.Unequipped:Connect(function()
if playing == true then
playing = false
track:Stop()
end
end)

math.floor(Character.HumanoidRootPart.Velocity.Magnitude) will give you the player speed. If it’s greater than 1, then they are moving.

How can I add this to my script?

I changed the script and only 1 animation plays… idk why

local playing = false
local tool = script.Parent

local anim = Instance.new(“Animation”)
anim.AnimationId = “http://www.roblox.com/Asset?ID=15902786962

local anim2 = Instance.new(“Animation”)
anim2.AnimationId = “http://www.roblox.com/Asset?ID=15902154245

local track = nil
local track2 = nil

tool.Equipped:Connect(function()
while wait(0.1) do
if math.floor(script.Parent.Parent.HumanoidRootPart.Velocity.Magnitude) > 1 then
playing = true
track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
track2.Priority = Enum.AnimationPriority.Action
track2.Looped = true
track2:Play()
if track then
track:Stop()
end
break
else
if math.floor(script.Parent.Parent.HumanoidRootPart.Velocity.Magnitude) < 1 then
if not track then
playing = true
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
if track2 then
track2:Stop()
end
break
end
end
end
end
end)

tool.Unequipped:Connect(function()
if playing == true then
playing = false
if track then
track:Stop()
end
if track2 then
track2:Stop()
end
end
end)

If you want an idle animation to play, make sure the animation priority is set to Idle.

I tried remaking your script, tell me if this version works:

local Players = game:GetService("Players")

local Tool = script.Parent

local Player
local Character

Tool.Equipped:Connect(function()
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)

	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Animator = Humanoid and Humanoid:FindFirstChild("Animator")

	if Humanoid and Animator then
		local animation = script.Animation
		local animationrack = Animator:LoadAnimation(animation)
		
		animationrack:Play()
		
		Tool.Unequipped:Connect(function()
			animationrack:Stop()
		end)
	end
end)

Here’s the full tool with script: ToolExample.rbxm (2.5 KB)

1 Like

This is useful, but I want to add a idle and a walk animation. How do I do this?

Also, changing the priority to Idle makes the arm look weird, this wasn’t a issue when it was Action I believe.

Never mind, I found a fix! I just used a different script and it works pretty good

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