Help with inverting controls [ROBLOX MODULES]

I want to be able to invert movement controls like with a switch. So if a bool value is true then pressing W will make you go backwards, while pressing S will make you go forwards.

For some context, I’m scripting an obby game and this is a modifier that will last only a few seconds, which is why I need the bool value as a switch to turn it on/off.

So far, I haven’t been able to do much. All I know is, it has something to do with the default modules inside every player, so I tried implementing this solution: similar topic

The problem is it doesn’t work, no errors either, on closer inspection I found that the move function that solution is trying to modify is part of a .new constructor function:

-- lines 107-123 inside Control module
function ControlModule.new()
	local self = setmetatable({},ControlModule)

	self.controllers = {}

	self.activeControlModule = nil	
	self.activeController = nil
	self.touchJumpController = nil
	self.moveFunction = Players.LocalPlayer.Move -- here's the function that has to be redirected
	self.humanoid = nil
	self.lastInputType = Enum.UserInputType.None
	self.controlsEnabled = true

	self.humanoidSeatedConn = nil
	self.vehicleController = nil

I’m not sure if it’s possible to change the move function because the table it is part of hasn’t even been created yet, the only possible ways I could think of is to either change the constructor function or the module by switching it out. And idk how to do either of them.

So, if you know how to create a system like this or have an easier solution to invert the player controls, please let me know.

1 Like

Look into this: How to make inverted controls?
Controls are handled by a script Roblox adds themselves. You can add your own custom version of this movement code to allow inverting.

1 Like

Yes, I looked at that post, the solution doesn’t work anymore. I’m asking how can I add my own custom version, and I only wanna modify that move function.

1 Like

You will need to make adjustments to Roblox’s movement code or write your own. I recommend the use of an attribute on the player or character that will be used inside the movement code to decide whether to invert the movement or not.
Unless you write a whole custom movement system, you will need to make edits to Roblox’s.

2 Likes

Yeah, but how do I edit those modules? The scripts only spawn when testing in studio.

1 Like

Copy them while playing in studio. If a script with the same name as the default Roblox script exists, Roblox does not insert a new one. Add it to the StarterPlayerScripts or StarterCharacterScripts, depending on what script you are using.

1 Like

The control module is parented to the player module, so do I have to copy that too? If roblox sees the player module already there, does it check for whether it has the other scripts parented to it?

1 Like

You will need to copy the entire bundle. Studio lets you copy the script from Explorer and paste it back in outside of testing. You do not need to copy the code from the script itself.

1 Like

Aight, tysm. I’ll get to work and edit this post when something comes up.

EDIT: It works! For those who want to know how I did it, I copy pasted the entire bundle of the player module into Starter Player scripts, and also added a bool value to be the ‘switch’, these are the changes I made to the control module:

function ControlModule.new()
	local self = setmetatable({},ControlModule)

	
	self.controllers = {}

	self.activeControlModule = nil	
	self.activeController = nil
	self.touchJumpController = nil
	self.invertedMovement = script.Parent.Parent:WaitForChild("InvertMovement") -- the bool value
	self.moveFunction = function(player, direction, relative)
		local mult = self.invertedMovement.Value and -1 or 1 -- negative one if true
		Players.LocalPlayer.Move(player, mult*direction, relative) -- the default function
	end
	self.humanoid = nil
	self.lastInputType = Enum.UserInputType.None
	self.controlsEnabled = true

The switch also works correctly in real time, no errors at all.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.