How do you temporarily disable all user inputs?

Is there a way to disable user inputs easily or do I have to listen to key input began event manually and somehow ground the default settings when some boolean variable is turned on?

1 Like

Take a look at ContextActionService:

You can bind/unbind functions to keys when they are needed / no longer needed respectively.

1 Like

I am trying to disable the default actions. How does the ContextActionService help? If when I am in cut scene play context, you listen to all user inputs and do nothing?

What do you mean by ‘default actions’? As far as I’m aware, you can’t override built-in keybindings (e.g. pressing Escape to open menu)

That’s something you can do, yes, apart from the Esc button and other actions in the CoreGui. You use BindActionAtPriority with a really high value for priority (see the ContextActionPriority enum) and then supply all the keycodes that you want to be ignored, then the function you bind would simply sink the input and do nothing else (return Enum.ContextActionResult.Sink).

3 Likes

Ok, let me explain it in simple terms. Bottom line, I just want to ignore all user inputs of all sources except for the ESC menu for a certain time. Maybe too extreme, then I would make couple more keys as exceptions. But for now, I would like to achieve that in the script and test things around.

Change the player’s WalkSpeed and JumpPower to 0 (freezes them)
Disable Chat & reset (So they cannot speak or reset).

^ If the user is on a computer.

Is this what you mean?

There is actually quite a hacky way to prevent all user input, this includes opening the escape menu, any click events etc. etc.

Here’s some code that I just wrote up that uses it:

local uinput do
	local a=false
	local tb=Instance.new("TextBox",game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"))
	function uinput(val)
		a=not val
		spawn(function ()
			while a==true do
				tb:CaptureFocus()
				game:GetService("RunService").RenderStepped:wait()
			end
		end)
	end
end

wait(2)
uinput(false)
wait(5)
uinput(true)

Not sure if this was what you were looking for but hope this helps.

EDIT: Just read the post above explaining what you wanted, if you’re talking about custom user input such as shooting a gun, opening a gui etc. then just have a variable that indicates whether or not those actions can be ran.

I chose FernandoMacLeod’s solution as the solution for my case because it was good enough for what I needed and the simplest. However all other responses in the threads are all very good suggestions. They could be used to do more complicated things. So please do not ignore other people’s solutions on here.

You can change a players “DevComputerMovementMode” / “DevTouchMovementMode” to “Scriptable”, which will disable their ability to walk / jump or whatever rather than having to use a hacky method.

You could just save what their movement mode was before you change it, then change it back to it when you’ve complete what you wanted to do.

1 Like