How do I detect if a player is moving backwards?

Were you looking for this? (It works on mobile as well):

https://developer.roblox.com/en-us/api-reference/enum/PlayerActions

Nvm figured it out. I just used the HumanoidRootPart’s CFrame.LookVector:Dot feature.
Thanks for helping though.

script :

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local hrp = char:WaitForChild("HumanoidRootPart")

local dir, vel

while wait(0.3) do
	vel = hrp.Velocity * Vector3.new(1, 0, 1)
	dir = vel.Unit
	
	if math.round(hrp.CFrame.LookVector:Dot(dir)) < 0 then
		print("walking Backwards!")
	end
end
4 Likes

Oh, I didn’t even know about this! But thanks!

1 Like

I’m kind of hesitant to use while loops on this as it can cause performance issues, but if it works for you then, it works.

To be honest, I just used this loop because I tried @kaizenmarcell 's script.

1 Like

How do I use this lol I’m a bit confused.

Simply just do this:

local ContextActionService = game:GetService("ContextActionService")

local function Backwards()
    print("I moved backwards, yay!")
end

-- Do not set it to true as even if it has a button, it'll only work when you move backwards.
ContextActionService:BindAction("Backwards", Backwards, false, Enum.PlayerActions.Backward)

I also want to ask why did you reply 12 days later?

1 Like

New game… Pretty much lol…