Stop Animation when Moved

Hello Developers!

So I learned how to make an animation play when I click a button, the following script here:

Script
wait(.5)
local frame=script.Parent
local user=game.Players.LocalPlayer
repeat wait() until user.Character local char=user.Character
local humanoid=char:WaitForChild("Humanoid")
local anim
function playanim(id)
	if char~=nil and humanoid~=nil then
		local id="rbxassetid://"..tostring(id)
		local oldanim=char:FindFirstChild("LocalAnimation")
		if anim~=nil then
			anim:Stop()
		end
		if oldanim~=nil then
			if oldanim.AnimationId==id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end
		local animation=Instance.new("Animation",char)
		animation.Name="LocalAnimation"
		animation.AnimationId=id
		anim=humanoid:LoadAnimation(animation)
		anim:Play()
		
	end
end
local b1=frame.OLButton
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) end)
local b2=frame.QBButton
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) end)
local b3=frame.TEButton
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) end)
local b4=frame.WRButton
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) end)
local b5=frame.CBButton
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) end)
local b6=frame.SafetyButton
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) end)
local b7=frame.LBButton
b7.MouseButton1Down:connect(function() playanim(b7.AnimID.Value) end)
local b8=frame.DLButton
b8.MouseButton1Down:connect(function() playanim(b8.AnimID.Value) end)

However, I want to make it that once the player has moved, or if more than 1 Walkspeed, then stop playing the animation. How would I do this?

I thought I could do something like this:

local speed=humanoid.WalkSpeed
if speed>1 then
	anim:Stop()
end

At the very bottom of the script.

However, that doesn’t work. Any help?

1 Like

Try this and see if this works

Humanoid.Running:Connect(function(Speed)
    if Speed  > 1 then
        anim:Stop()
    end
end)

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