How to detect if a player is moving

I want to make a tool script that when a player equips it changes the players walkspeed and then changes the players walk animation and reverts everything back once they unequip.

The player’s walkspeed gets lowered but the the walk animation doesn’t change whatsoever.

I have tried changing the players walk animation in the animate script when the tool gets equipped but it doesn’t work.
Edit: I used Humanoid.MovementDirection but now it starts playing the walk anim as soon as the player equips and doesn’t stop when unequipped.
I placed the new script below

local Animation = script.Walk
script.Parent.Equipped:Connect(function()
	local Humanoid = script.Parent.Parent:WaitForChild("Humanoid")
	local LoadedAnimation = Humanoid:LoadAnimation(Animation)
	LoadedAnimation:Play()
	Humanoid.WalkSpeed = 4
	if Humanoid.MoveDirection.Magnitude >= 0 then
		LoadedAnimation:Play()
	elseif Humanoid.MoveDirection.Magnitude == 0 then
		LoadedAnimation:Stop()
		end
end)
script.Parent.Unequipped:Connect(function()
    local Name = script.Parent.Parent.Parent.Name
	local character = game.Workspace:FindFirstChild(Name)
	local Humanoid = character:WaitForChild("Humanoid")
	local LoadedAnimation = Humanoid:LoadAnimation(Animation)
	LoadedAnimation:Play()
	Humanoid.WalkSpeed = 16
	local AnimateWalk = character:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
	AnimateWalk.AnimationId = "rbxassetid://913402848"
end)
1 Like

you told the game to play the Animation when you equipped the tool at line 5

and you didnt told the game to stop the animation when unequipped

i dont see animation:Stop() anywhere when you unequipped the tool

so what your telling the game to do here is

when the tool is equipped fire this function ONCE

which means it checks ONCE for if MoveDirection.Magnitude >= 0

and if you want this if statement to fire While the tool is equipped then you should use a… i dont know

runService:BindToRenderStep(“ThisBind”) maybe
and you could do
runService:UnbindFromRenderStep(“ThisBind”) when you want to revert everything back to normal

and also LoadedAnimation:Play() does not change the animation but just play it

2 Likes

if magnitude is 0 then both of them will run

1 Like

Take the script from this: Speed Coil - Roblox

why are you showing me a speed coil?

As you mentioned, you want a tool that when a player equips, it changes the player’s walk speed. Add your animation to the script, and you have yourself an animation/walk speed change tool!

-ItsKoolPlayz

wait what :sweat_smile:
the original post was made by @misesunny

OMG LOL! I DIDN’T NOTICE THAT I REPLIED TO YOU :sweat_smile:

1 Like