Help With Moving

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!
    The player in my game follows a Humanoid:MoveTo(goal). I want it so when the player walks towards it, he can not walk backwards, only forward and to the sides.

  2. What is the issue? Include screenshots / videos if possible!
    The player is in the MoveTo() loop, but he can just walk backwards and I don’t want that.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Everything I could think of, and I’ve searched for hours on devforums, discord servers, etc.

Here is the code that changes movement, I have another script that makes the player moves toward a part when a button is pressed. That script is just a simple Humanoid:MoveTo(goal.Position)
and btw the function is being called always and the moving sideways works perfectly, it’s just the forward and backwards that don’t work together with the MoveTo()

-- 	local function Move()
		local UserInput = UserInputService:GetFocusedTextBox()
		if UserInput then return end -- If typing, etc.

		local cameraForward = workspace.CurrentCamera.CFrame.LookVector
		local movingDirection = humanoid.MoveDirection
		local dotProduct = cameraForward:Dot(movingDirection)

		local rightVector = game.Workspace.CurrentCamera.CFrame.RightVector

		if dotProduct < -0.5 then -- player tries to move backward
			humanoid:Move(, 0, 0), false)
		elseif dotProduct > 0.5 then -- player tries to move forward
			humanoid:Move(, 0, 0), false)
		elseif UserInputService:IsKeyDown(leftKey) then
			local adjustedVector =, rightVector) * CFrame.Angles(0, math.rad(-30), 0)
			humanoid:Move(-adjustedVector.LookVector * speed, false)
		elseif UserInputService:IsKeyDown(rightKey) then
			local adjustedVector =, rightVector) * CFrame.Angles(0, math.rad(30), 0)
			humanoid:Move(adjustedVector.LookVector * speed, false)
			humanoid:Move(, 0, 0), false)

This should help you a bit.


Thanks, it works great! I do not use Replicated Storage or Replicated First at the moment, and as of the mobile thing, Idk what im gonna do about it, but i’ll figure something out when I get to that part. Thank you for your help :smiley:

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