How to detect if the player is walking forwards or backwards?

You can use cframe direction rotation to get what your looking for

local char: Model = script.Parent
local Hum: Humanoid = char:WaitForChild("Humanoid")
local HumRP = char.PrimaryPart

Hum.Running:Connect(function()
	local directive = HumRP.CFrame:VectorToObjectSpace(Hum.MoveDirection)
	
	if directive.Z < 0 then
		print("Going forward")
	elseif directive.Z > 0 then
		print("Going Backward")
	end
end)

Edit: this script was placed in startercharacterscripts

11 Likes