How to know when a player tries to move

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear! - I want my script to realise when my player tries to move

  2. What is the issue? Include screenshots / videos if possible! - im relatively new to scripting and i dont know how to achieve this

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? - i tried looking through all the properties of a humanoid and there arent any properties that show me if the player is trying to move

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Ok so here’s the full issue - im trying to make an animation gui and its working perfectly except for the fact that my player can walk while the animation is running, so i planned on setting the walkspeed to 0 when the animation is running and to set it back to 16 when the player tries to move again, the problem is that i dont know how to detect when the player tries to move his character, im sorry if this is a dumb question im quite new to scripting

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

After a quick search i found out that the humanoid of the player has a property called: MoveDirection.
If it’s value is greater than 0 then the player is moving.

1 Like

MoveDirection cannot determine when a player has Moved or stopped moving this only calculates the direction in which a players goes in a x and z axis wdym lol

wdym it would work just fine

This text will be blurred

Broooo it clearly says in the API that it tells the direction in which a player is going in a x or z axis it cannot tell when a character has stopped moving or not

in the hyperlink i posted there is A literal line that says:

if humanoid.MoveDirection.Magnitude > 0 then – Are we walking?

2 Likes

Anyways @sne_12345678 You can calculate such by checking if the HumandRootPart is at the same position for 5 seconds it fires an event that you want

You do know Magnitude is the distance between stuff right what does it have to do if a Humanoid has stopped moving

Ok so this is a local script that must be in starterCharacterScripts i clearly borrowed from the link

local RunService = game:GetService("RunService")

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function IsWalking()
	wait(0.2)
	if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
		print("Walking")
	end
end

RunService.RenderStepped:Connect(IsWalking)

I tested it and it works

if you want to stop the player from moving while the animation is playing, do this:

animation:Play()
hummanoid.WalkSpeed = 0
animation.Ended:Wait()
humanoid.WalkSpeed = 16

if Humanoid.MoveDirection.Magnitude > 0 then

2 Likes

but the player might want to walk in the middle of the animation and it should stop whenever he tries to walk

the humanoidrootpart may also move during the animation though

Humanoid.MoveDirection.Magnitude does the job for this, it is equal to 0 when the character isn’t moving.

Thanks so much it worked! heres the script i used:

for i,v in pairs(game.Workspace:GetChildren()) do
	if v:IsA("Model") then
		if v:FindFirstChildWhichIsA("Humanoid") then
			local humanoid = v.Humanoid
			while true do
				if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
					print("he moved")
				end
				wait()
			end
		end
	end
end
2 Likes