I also need this script to be compatible with mobile so I don’t really know how to do that.
This prints every 0.3 seconds the player is walking backwards.
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
while wait(0.3) do
if humanoid.MoveDirection.Z > 0 then
print("Player is moving backwards")
end
end
Alright I’ll try it. [ Filler ]
It doesn’t work sorry. When you walk backwards on the X-axis it doesn’t seem to work.
It works, I know that. If not something is wrong with your script or game.
It’s probably because my game is in first person.
Have you copied my script and tried it? It should not have anything to do with it being in first person. If you walk backwards with the ‘S’ key it prints.
But the thing is this game needs to be compatible with mobile. So I don’t really know how to do that.
It is compatible with mobile, the script
Yep [ Filler again cause it’s way too short ]
But I am trying to figure out a way using the HumanoidRootPart’s CFrame.LookVector:Dot feature.
There are a bunch of topics made with this exact title. Use the search bar.
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
Oh, I didn’t even know about this! But thanks!
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.
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?
New game… Pretty much lol…