Disabling controls than enabling again does not enable

So i am trying to make the player lose control than gain control again but when its enabled i cannot move my player anymore.

local controls =require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
            controls:Disable()
            wait()
            controls:Enable()
9 Likes

The correct function usage is ControlModule:Enable(Bool)

Your code would work if you included a true bool in the Enable function.

local controls =require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
            controls:Disable()
            wait()
            controls:Enable(true)

The Disable function has no expected arguments. For those curious, including a logically false (false, nil, etc.) value in Enable… disables the active control module.

There are some other issues with your code (e.g. indentation, format, etc.) but that is beyond the scope of this reply, please ask me if you need advice with that.

If this reply has helped you, please mark it as a solution by pressing the :white_check_mark: button below

17 Likes

Try doing this instead. I’m not too familiar with disabling player controls using that module but I tested it and it seems to work. It takes a bool value and the bool value you put in is the result you will get.

repeat wait() until game.Players.LocalPlayer

local controls =require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Enable(false)
wait(5)
controls:Enable(true)

Also, you were running it instantly which could possibly run before the player even loads so it’s always a good idea to verify the player is there.

1 Like

The thing is, the code seems to work fine with just controls:Enable(). It just seems to entirely disregard the controls on respawning. I was only able to grant myself movement again by forcing this with the command bar for some reason, having a localscript doing the exact same by the press of a button however did not.

2 Likes

I was just about to post a message regarding this same issue.

@Dynastorious - have you been able to find a resolution on this?

@KingOfGenres had posted the same issue months ago, but unfortunately, his thread just ended with no resolution. @KingOfGenres - did you ever find a resolution for this? Your thread is here:

Post Of Same Issue

Repro Created
I am having the same issue and have made a repro for it.

controls-repro.rbxl (21.3 KB)

You could see it live as well here:

I have a few lines of instructions to reproduce the issue.

I’m running out of things to try and feel like either I dont’ know what I don’t know, or there is an existing bug on this.

Thank you.

1 Like

@Dynastorious - unfortunately, I just noticed you had set this to resolved, but the solution listed does not seem to be the issue in my case. I might open a new post and go with that instead.

@tragoblue Not my post, wasn’t me that set it to solved. Alas I was unable to find a decent fix for this so I commented it in my code and went with just changing walkspeed for now, hoping a decent solution would come.

To confirm; your issue is the system overriding Controls:Enable(false) on respwn?

Basically, you can disable and enable movements on the character via the PlayerModule’s Controller.

It works great, that is unless you die and respawn prior to re-enabling the movenents, at which case, you will not be able to regain movement by calling the enable().

There has been suggestions to use other things such as binding actions, using priorities, using walkspeeds, but all of these solutions smell to me. The PlayerModule was changed/enhanced a few months back and should be the only way to do this without requiring surgical work. I have submitted a bug report to Roblox so I’m hoping to get some feedback from them on this issue.

@Dynastorious - oh, sorry, I thought this was your post. Yeah, unfortunately, I might have to look for some other workaround to get this behavior (perhaps what you said about the Walkspeed).

[EDIT]
FYI, in case anyone finds this post with same problem as mine, I went with this solution:

(credit to @TheGamer101 )

local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"

ContextActionService:BindAction(
FREEZE_ACTION,
function()
    return Enum.ContextActionResult.Sink
end,
false,
unpack(Enum.PlayerActions:GetEnumItems())
)

-- To unfreeze movement:

ContextActionService:UnbindAction(FREEZE_ACTION)

It worked as expected.

6 Likes

You should. The OP’s solution was solved, yours is very different and likely a bug.

use a repeat wait() until player:FindFirstChild(“PlayerModule”)