I am relatively new to Roblox scripting, and I want to move the player forward according to the direction they’re facing when they click on a part. The only problem is that I don’t know how to script that. I cannot find any solutions to what I am asking online. Help would be appreciated!
The player character is a model, where if you try to change the position of any one part, it will not effect the rest of the model. To move an entire model, you must change the CFrame of it’s PrimaryPart (which in a player is the HumanoidRootPart).
The “forward” direction in roblox is the negative Z direction, so you can move the player with:
all baseparts in roblox have a CFrame and all CFrames have three direction vectors. LookVector is the one that points in the forward direction (the direction the block is facing). There are also RightVector and UpVector. And if you want to go in the opposite direction of any of those you can just multiply them by a negative number.
you can use the player camera’s direction (only on local scripts)
local plyrCam = game:GetService("Workspace").CurrentCamera
hrp.Position = plyrCam.CFrame.LookVector * 5
------------EDIT-------------
No biggy but i just remembered that you dont need to move the HRP to move a character model. You can use a function that all models have.
local char = player.Character
local ppCF = char:GetPrimaryPartCFrame()
char:SetPrimaryPartCFrame( ppCF.LookVector * 5 )