Animations are not playing correctly

What i’m trying to do is have an idle animation play when the tool is equipped, and when I walk with the tool equipped, a walking animation triggers, but when I stop the idle animation triggers. What’s happening is when i walk, the walking animation triggers, but does not turn off. Also, when the tool is unequipped, the walking animation is still playing when i move.

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

local combat = script.Parent
local anim = humanoid:LoadAnimation(combat:WaitForChild("idle"))
local walk = humanoid:LoadAnimation(combat:WaitForChild("walking"))

combat.Equipped:Connect(function()
		anim:Play()
	humanoid.Running:connect(function(speed)
		if speed > 10 then
				anim:Stop()
				walk:Play()
		if speed < 2 then
				walk:Stop()
				anim:Play()
			end	
		end
	end)
end)	
combat.Unequipped:connect(function()
	anim:Stop()
	walk:Stop()
end)

Help is must appreciated :+1:

2 Likes

You could instead try checking if the humanoid moveto is not equal to 0,0. That means they are walking, otherwise check if the tool is also equipped then let the animation play, i’ll try and type up a script that might work, i’m on mobile so i can’t test it.

1 Like

I’m days new to scripting, so i’m not very familiar with Roblox API, How would I implement MoveTo into the script?

1 Like

from my understanding whats happening here is that the Running event is not getting disconnected also im guessing theres a typo in the if statements, since speed cant be > 10 and < 2?

Possible solution (hopefully):

local connection;
combat.Equipped:Connect(function()
	anim:Play()
	connection = humanoid.Running:connect(function(speed)
		if speed > 10 then
			anim:Stop()
			walk:Play()
		elseif speed < 2 then
			walk:Stop()
			anim:Play()
		end
	end)
end)	
combat.Unequipped:connect(function()
	anim:Stop()
	walk:Stop()
	connection:Disconnect()
end)
1 Like

Sorry I read this late, I for some reason had to refresh my page to see it, but thanks so much for the help, it worked!

1 Like
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local mouse = game:GetService("UserInputService")

local combat = script.Parent
local idle = humanoid:LoadAnimation(combat:WaitForChild("idle"))
local walk = humanoid:LoadAnimation(combat:WaitForChild("walking"))


while wait(0.5) do

if player.Character.Humanoid.WalkToPoint == Vector3.new(0,0,0) and combat.Parent == player.Character then
--Equipped and idle
walk:Stop()
idle:Play()
elseif player.Character.Humanoid.WalkToPoint ~= Vector3.new(0,0,0) and combat.Parent == player.Character then
--Equipped and not idle
idle:Stop()
walk:Play()
end
--Is there any other scenarios like if its not equipped should the animation still play?

I changed anim to idle so its easier for me to work, yet this is how i would do it, your method may work, ill try and debug it if this method doesn’t work or you don’t want to use it.

1 Like

Ah nvm, i see you got it to work. Glad to see!

Sorry that I made you do all of that, I really am! But if anything comes to an error/issue, i’ll for sure come back to this post to look at what you’ve given me. Your work will be put to use!

Its all good, lol. I’m not even sure it works, i’ll try it out tomorrow and let you know!