How to temporarily disable all character input?

My goal is to disable the all characters input for a small scene. The reason the walkspeed cannot be set to 0 is because the character will be moving/jumping during that cutscene.

for _, controller in pairs(game:GetService("ControllerService"):GetChildren()) do
        controller.Parent = nil
end
player.PlayerScripts.ControlScript.Disabled = true

The first function does not seem to work. The problem with the second one is that the character moves the direction you were heading after it’s enabled again. So the character would move that direction when enabled until another userinput was fired like pressing w again.

21 Likes

You can use ContextActionService to do this. This disables the PlayerActions and works with both Controller and Keyboard.

Edited to fix per @buildthomas’s post

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

ContextActionService:UnbindAction(FREEZE_ACTION)
86 Likes

You can also change their player’s movement mode from UserChoice to Scriptable. On wiki as DevComputerMovementMode and DevTouchMovementMode. This might be slightly more useful because it can be set from the server as well and it makes sense since it is Scriptable.

16 Likes

Thank you.

1 Like

I’ll look into that too.

1 Like

For the record for anyone reading this, this code actually doesn’t work like this because of a bug:
https://devforum.roblox.com/t/contextactionservice-callback-needs-to-explicitly-return-sink-enum-when-bound-to-playeractions-to-actually-sink-inputs/179231

The working code is the following:

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

ContextActionService:BindAction(
    FREEZE_ACTION,
    function()
        return Enum.ContextActionResult.Sink -- need to explicitly return this
    end,
    false,
    unpack(Enum.PlayerActions:GetEnumItems())
)

--to unfreeze

ContextActionService:UnbindAction(FREEZE_ACTION)
24 Likes

These solutions will work, but I thought I’d add an easy way to do this if you’re using the default ControlScript. First you’ll want to copy the default ControlScript from a player and put it into PlayerScripts. It contains the MasterControl ModuleScript, which you can require to access some functions for controlling input to the character.

local player = game.Players.LocalPlayer
local masterControl = require(player.PlayerScripts:WaitForChild("ControlScript"):WaitForChild("MasterControl"))
masterControl:Disable()
wait(3)
masterControl:Enable()
print("voila!")
4 Likes

I would argue this way isn’t easier, it just relies on scripts existing which may not always exist unless you fork the default scripts, which you shouldn’t do.

@buildthomas’ code works fine, and doesn’t rely on any other scripts existing.

This will stop working in the future because they are revamping the layout of the control/camera scripts, FYI.

1 Like

I don’t think this works anymore

1 Like

Nvm it just doesn’t work with gamepad

1 Like

I don’t know if necrobumping is allowed, but

I’m replying to someone else with that comment, the code I posted should be working.

1 Like

My comment was removed because I accidentally asked it twice, so I’ll ask it again but once this time.

Does this also work on mobile?

1 Like

I used this before but it doesn’t work for mobile players and sometimes it makes you move one direction by itself…

2 Likes

How would I also disable mouse input? Been trying to set up an animated cutscene thing but I can’t get it to work properly without disabling the player’s mouse input so they can’t move the camera while the cutscene (animation) is playing

Maybe set the camera to “Fixed” or “Scriptable”?
If it NEEDS the Humanoid’s “Custom” camera type, maybe you should rewrite the cutscene system you use to fit the types mentioned.
In Fixed, the mouse works, but the camera is immovable.
In Scriptable, the mouse also works, but the camera is immovable to all except Scripts.

This only works for keyboard controls.

3 Likes

What about mobile games?! This is only pc and not console either!!!