Ad
Log in to vote
0

Help with detecting which direction the player is moving?

Asked by
NykoVania 198 Moderation Voter
21 days ago
Edited 21 days ago

I want to detect which direction the player is moving, but only the Z axis works, which detects forwards and backwards movement.

Script:

local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Char:WaitForChild("Humanoid")
local HumRP = Char.PrimaryPart


while wait() do
    local directive = HumRP.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
    if directive.Z < 0 then
        print("Going forward")
    elseif directive.Z > 0 then
        print("Going Backward")
    end
end

But when I change Z to X and move side to side it also prints forwards and backwards for some reason. Any help? Script:

while wait() do
    local directive = HumRP.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
    if directive.X < 0 then
        print("Going right")
    elseif directive.X > 0 then
        print("Going left")
    end
end

Answer this question