How to disable player controls with new PlayerScript layout?

I’m struggling to understand how to do this with the very limited amount of information about how to use the new PlayerScripts layout.

I used to disable the ControlScript outright but I’m unable to do this since the update, any advice?

Cheers.

EDIT: Might I add I specifically mean movement controls E.G W-A-S-D.

13 Likes

Hayo!

The new player module layout is shown below.

Previously, you would disable the Control script as a hacky way to disable movement.
With the new PlayerModule comes improved functionality.

In order to disable controls, you would need to require the player module, get the controls, and run the Disable method. This can only be used locally

-- This require statement gathers the new player scripts.
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))

-- In order to access controls, you must first get the controls
local Controls = PlayerModule:GetControls()
-- For Cameras, use PlayerModule:GetCameras()

--[==[ You have now obtained the new control methods! Yay! ]==]--

-- In order to enable controls, you need to use the reference Controls instance and call the Enable method within it.
Controls:Enable()

-- In order to disable controls, you need to use the reference Controls instance and call the Disable method within it
Controls:Disable()

I’d believe that more documentation over the new PlayerScripts will be created, but for now limited documentation exists, seen here

If you have any more questions or if I made an error, please reply to this message.

Thanks!

68 Likes

Ah thank you, this worked well, very useful!

3 Likes

Ok I know I’m necroing this but I have something to add.

Controls:Disable() (or Controls:Enable(false)) only disable the currently active controller! This means if a player switches from keyboard to gamepad, or between any two distinct “controllers” in the player module, the new one will be enabled, i.e. the player will regain control of their character if they simple swap input method.

I’m not sure if there is an elegant way to get around this, but if you want to guarantee that a player can’t move it’s still probably best practice just to set WalkSpeed to 0.

15 Likes

If the Controls:Enable() doesn’t work be sure to use Controls:EnableActiveControlModule()

3 Likes

You can overwrite it! Just sure it same the name!

1 Like