How to stop processing user input but when turned back on, the input still being active will play

  1. What do you want to achieve? Keep it simple and clear!
    I want to temporarily turn of user input or at least selected keycodes, but on turning it back on it will take in the input before the turn off or during the turn off.
  2. What is the issue? Include screenshots / videos if possible!
    I am not sure how to achieve turning off input then checking what input is being pressed during or before the turn off effectively.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried contextActionService but it only achieves one of two things which is turning off input but turning input back on it, does not register BEFORE or DURING keys being pressed until I apply input AFTER I turn user input back on.

I am trying to make a combat system so I am wanting the character to be in states like stunned (so they can’t walk away or attack back ) or in attacking (so they can’t jump).
Best game examples is battlegrounds games basically.

My Module script for turning on and off input for ContextActionService (but I made this like 5 months ago because I could not solve the problem I am asking to solve in this post).


local ContextActionService = game:GetService("ContextActionService")
local Input = {}

 function Input.disableUI(Name,Function,inputobject) 


    return Enum.ContextActionResult.Sink --and print("denied input")
end

function Input.Disable_Now()
    ContextActionService:BindAction("disablednow",Input.disableUI,false,Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.Space,Enum.KeyCode.One,Enum.KeyCode.Two,Enum.KeyCode.Four)
--print("disabled now")
end

function Input.Enable_Now()
    ContextActionService:UnbindAction("disablednow")
--print("enabled now")
end



return Input

Record the previous input in a variable and when you enable the inputs again you can see it

we wouldnt be able to help easily if you dont atleast show a screenshot or a vid or your script

Here is a script I did awhile ago when trying to use ContextActionService. When I re-enable it does not take in the keycodes that are being pressed. Do I have to use Roblox built-in module scripts for handling user input for the character?

If you want, you can also just toggle their controls with this:

local player = game.Players.LocalPlayer
local PlayerModule = require(player.PlayerScripts.PlayerModule)
local Controls = PlayerModule:GetControls()

-- Walking is enabled
Controls:Enable()

-- Walking is disabled
Controls:Disable()

You can keep the ContextActionService stuff if you wanna disable the 1, 2, 3, 4 keys since holding them shouldn’t be a problem.

I’m not sure if I need to add to it but when I tried out your script here it still does not re-register whats being pressed. Do I have to try make this myself or is it somewhere in a script that Roblox has provided.

In this video I have the output print anything I press and an indicator of disabling and enabling the script and the whole time I was holding down “A” after it was re-enabled and only started moving when I pressed the “A” key again. I just really want to know how Roblox can pick it up and apply it, just movement, jump and mouse click.

Sir i think the w bind is your movement bind so when you try to move it will activate