Messing up movement

so ive been trying for a few hours now, enabling, destroying , cloning , smashing my Mac to bits but I cannot work out a way to mess around with the roblox movement script e.g. when ‘w’ is pressed you more backwards when ‘a’ is pressed you move right. does anyone have a solution to this?

1 Like

Are you looking to change the control scheme? You’ll have to fork the ControlScript to accomplish this. Once that’s done, you can just make changes to the script as needed, whether to support external control changes or to have the changed controls permanent.

To fork:

  • Start a new place and start a play solo session
  • Open up StarterPlayerScripts and copy ControlScript
  • Stop the session and paste the script into StarterPlayerScripts
  • Edit
  • (Alternatively) Convert the code from the StarterPlayerScripts repository and make changes

The specific module in the ControlScript you’re looking for is Keyboard. The function in which binds movement directions to keys is BindContextActions. Look to the bottom of the function to find what you need.

1 Like

I know how to get the modules into studio so I can work on them but im having major problems messing up the movement, then changing it back since its almost impossible to terminate a module script

Don’t try to terminate the ModuleScript. Create a method in your forked ControlScript that exposes methods to allow you to rebind control schemes.

1 Like

hm let me try that real quick, I tried rebinding using string values but that failed but maybe if I use a bool and create a fork in the script that could work

You can use BindContextActions as a base. You can add four parameters which allow you to specify which keys to use, then at the bottom where it uses ContextAction to bind actions, use the keys you specified instead. You have to unbind previous actions first though.

1 Like

can you show a screenshot or something of the block of code ur currently specifying

function Keyboard:BindContextActions()

	local updateMovement = function(inputState)
		if inputState == Enum.UserInputState.Cancel then
			self.moveVector = ZERO_VECTOR3
		else
			self.moveVector = Vector3.new(self.leftValue + self.rightValue, 0, self.forwardValue + self.backwardValue)
		end
	end
	
	-- Note: In the previous version of this code, the movement values were not zeroed-out on UserInputState. Cancel, now they are,
	-- which fixes them from getting stuck on.
	local handleMoveForward = function(actionName, inputState, inputObject)			
		self.forwardValue = (inputState == Enum.UserInputState.Begin) and -1 or 0
		updateMovement(inputState)
	end
	
	local handleMoveBackward = function(actionName, inputState, inputObject)	
		self.backwardValue = (inputState == Enum.UserInputState.Begin) and 1 or 0
		updateMovement(inputState)
	end
	
	local handleMoveLeft = function(actionName, inputState, inputObject)	
		self.leftValue = (inputState == Enum.UserInputState.Begin) and -1 or 0
		updateMovement(inputState)
	end
	
	local handleMoveRight = function(actionName, inputState, inputObject)	
		self.rightValue = (inputState == Enum.UserInputState.Begin) and 1 or 0
		updateMovement(inputState)
	end
	
	local handleJumpAction = function(actionName, inputState, inputObject)
		self.isJumping = (inputState == Enum.UserInputState.Begin)
	end
	
	-- TODO: Revert to KeyCode bindings so that in the future the abstraction layer from actual keys to
	-- movement direction is done in Lua
	ContextActionService:BindAction("moveForwardAction", handleMoveForward, false, Enum.PlayerActions.CharacterForward)
	ContextActionService:BindAction("moveBackwardAction", handleMoveBackward, false, Enum.PlayerActions.CharacterBackward)
	ContextActionService:BindAction("moveLeftAction", handleMoveLeft, false, Enum.PlayerActions.CharacterLeft)
	ContextActionService:BindAction("moveRightAction", handleMoveRight, false, Enum.PlayerActions.CharacterRight)
	ContextActionService:BindAction("jumpAction",handleJumpAction,false,Enum.PlayerActions.CharacterJump)
end

From the GitHub file I posted above.

2 Likes

ye this is what im currently working with since from what ive discovered all I need to change is the ‘handleMove…’ part. im just having issues with rebinding them

You’re changing the wrong thing. Don’t change those, change the bindings.

    ContextActionService:BindAction("moveForwardAction", handleMoveForward, false, Enum.PlayerActions.CharacterForward)
	ContextActionService:BindAction("moveBackwardAction", handleMoveBackward, false, Enum.PlayerActions.CharacterBackward)
	ContextActionService:BindAction("moveLeftAction", handleMoveLeft, false, Enum.PlayerActions.CharacterLeft)
	ContextActionService:BindAction("moveRightAction", handleMoveRight, false, Enum.PlayerActions.CharacterRight)
	ContextActionService:BindAction("jumpAction",handleJumpAction,false,Enum.PlayerActions.CharacterJump)
2 Likes

I worked it out now , thx! your help was rlly appreciated :smiley: