How to move player foward based on their direction

So I want to create a script that moves the player foward based on the direction they are looking, so no matter which way they are facing they will always move - on the Z axis.

I have severall attempts at this, all of which have failed, so I am here.

Here is my code:

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")

wait(6)
print("Moving")
--h:MoveTo(char:WaitForChild("HumanoidRootPart").CFrame.LookVector * CFrame.new(0,0,5).Position)
--game.Players.LocalPlayer:Move(Vector3.new(0, 0, -5000), false)
--h.WalkToPoint = char.HumanoidRootPart.CFrame.Position + (char.HumanoidRootPart.CFrame.LookVector * Vector3.new(0, 0, 20))
h:MoveTo(char.HumanoidRootPart.CFrame:ToObjectSpace(CFrame.new(0,0,20)))

The comments are my other failed attempts

All help appreciated! :slightly_smiling_face:

1 Like

I need to force the player to walk using “:MoveTo()”

Using :ToWorldSpace should work.

Also, I suggest using :PointToWorldSpace(Vector3.new(0,0,20))

The solution I needed apparently needed a BodyVelocity, but I will give you the solve anyways! :+1:

1 Like

I think you should probably mark your post as the solution :stuck_out_tongue:

1 Like