Script Disable and Enabled InputKeys

I would like to disable some keyboard inputs and enable them again after a certain time.
ModuleScript

local UIS = game:GetService("UserInputService")

local DisabledInput = {}

-- Proměnná pro definování klávesových zkratek
local inputKeys = { 
    ["One"] = {txt = "1"},
    ["Two"] = {txt = "2"},
    ["Three"] = {txt = "3"},
    ["Four"] = {txt = "4"},
    ["Five"] = {txt = "5"},
    ["Six"] = {txt = "6"},
    ["Seven"] = {txt = "7"},
    ["Eight"] = {txt = "8"},
    ["Nine"] = {txt = "9"},
    ["Zero"] = {txt = "0"},
    ["Ocko"] = {txt = "O"},
}

-- Stav zakázání kláves
local keysDisabled = false

-- Funkce pro zakázání kláves
function DisabledInput.DisableKeys()
    keysDisabled = true
end

-- Funkce pro povolení kláves
function DisabledInput.EnableKeys()
    keysDisabled = false
end

-- Hlavní funkce pro zpracování vstupu
local function disabledKeyPress(inputObject)
    if keysDisabled then
        local key = inputObject.KeyCode.Name
        if inputKeys[key] then
            print("Klávesa " .. inputKeys[key].txt .. " je zakázaná.")
            return
        end
    end
end

-- Připojení ke vstupní události
UIS.InputBegan:Connect(disabledKeyPress)

return DisabledInput

and then disable and enable them on the server side

local DisabledInput = require(game.ServerScriptService.DisableInput)

DisabledInput.EnableKeys()
DisabledInput.DisableKeys()

but somehow it’s not working for me

Thanks in advance for your help

Codycheck

1 Like

I believe that you need to make use of RemoteEvents in order to inform the client of the changes.

In a local script, listen out for the remote event being fired, and use the fired event to enable / disable the keys.

On the server side, you should simply fire the remote event using :FireAllClients, and pass along whether they should enable or disable the inputkeys

thanks for the direction
I still had to create some more functions there, but it works.
In the ServerScript

disableEnableKey:FireClient(player) -- Pošle povolení kláves do LocalScriptu
disableDisableKey:FireClient(player) -- Pošle zakázání kláves do LocalScriptu
disableDisableKey.OnClientEvent:Connect(function()
    disableKeyPress()
    print("Klávesy zakázány v MANAGER.")
end)

-- Posluchač pro povolení kláves
disableEnableKey.OnClientEvent:Connect(function()
    enableKeyPress()
    print("Klávesy povoleny v MANAGER.")
end)

The player is now disarmed but protected when using the ATM

Thanks