Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to detect when a player is moving?

So I was playing one of those speed city games and I though I could probably make one of those so I tried to make a moving detection script cause thats pretty much the entire game lol but I cant get mine to work, I know there are plenty of easier ways to make one compared to mine but I dont understand them that well (Basically I would need a really in depth explanation) , but here's mine I also placed the script in the StarterCharacterScripts

local moving = false -- Moving Variable

function movingdetection() -- Function for detecting when player is moving
	if script.Parent.Humanoid.MoveDirection == Vector3.new(0,0,0) then	 -- Checking if they are moving in any direction
		local moving = false
	else
		local moving = true
	end

end

while true do -- Loop for constantly calling the moving detection function
	print("ok then")
	movingdetection() -- Calling the function
	if moving == true then -- Seeing if the player moving comes back true
		print("moving") -- To show that its working	
	end
	wait(0.5)
end

1 answer

✓ Accepted answer

There are two ways (or more idk):

This includes MoveDirection:

Character.Humanoid.Changed:Connect(function()
	if Character.Humanoid.MoveDirection.Magnitude ~= 0 then
		-- moving
	else
		-- not moving
	end
end)

There's also an event:

Character.Humanoid.Running:Connect(function(walkspeed)
	--Running
end)

Whatever fits your script the most.

This discussion is preserved as it was. New answers, comments, and votes are closed.