Inverse Movement

Hello, recently for one of my games I needed to switch the left and right movements of my players, this would make walking left actually make them walk right, and walking right actually make them walk left.

This is the current code I have

local ContextActionService = game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local HRP = player.Character:WaitForChild("HumanoidRootPart")

local function moveLeft(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("Rigt Began")
		humanoid:Move(Vector3.new(10, 0, 0), false)  
	elseif inputState == Enum.UserInputState.End then
		print("Right Ended")
		humanoid:Move(Vector3.new(0, 0, 0), false)
	end
end

local function moveRight(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("left Began")
		humanoid:Move(Vector3.new(-10, 0, 0), false) 
	elseif inputState == Enum.UserInputState.End then
		print("Left Ended")
		humanoid:Move(Vector3.new(0, 0, 0), false)  
	end
end

ContextActionService:BindAction("MoveLeft", moveLeft, false, Enum.KeyCode.A)
ContextActionService:BindAction("MoveRight", moveRight, false, Enum.KeyCode.D)

The player just stands still whenever pressing left and right

Input began and Input Ended work, its only the Humanoid:Move that is not working.
Ive tried changing the values to increase the vector 3.new value.

It would be very helpful if someone could explain how to do this. Thank you

According to the documentation on the move function -

if the default control scripts are being used, this function will be overwritten when called on player Characters. This can be avoided by either not using the default control scripts, or calling this function every frame using RunService:BindToRenderStep()


So something like this should work:

local function moveStop()
	RunService:UnbindFromRenderStep("move")
end

local function moveBegin(moveTarget)
	moveStop() -- Stop any old movements
	RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
		humanoid:Move(moveTarget, false)
	end)
end

local function moveLeft(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		moveBegin(Vector3.new(10, 0, 0)) 
	elseif inputState == Enum.UserInputState.End then
		moveStop()
	end
end

local function moveRight(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		moveBegin(Vector3.new(-10, 0, 0))
	elseif inputState == Enum.UserInputState.End then
		moveStop()
	end
end