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?
Take a look at ContextActionService:
You can bind/unbind functions to keys when they are needed / no longer needed respectively.
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
).
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.