How do i disable x key

how do i disable the x key?
(I made the x key print out a text and i want the x key to be disabled at a certain time)

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

Controls:Disable()
1 Like

that disables all controls i only want one control to be disabled

Use ContextActionService and bind the keyword X to a function that does literally nothing

will that override the other functions that are connected with x?

Well, if you used userinputservice to print something whenever x is pressed, it probably won’t get overrided.
I suggest you use ContextActionService for both the printing and disabling.
Or maybe you can just disable the script that prints something when x is pressed?
Or simply add a if then statement to check if x is disabled or not?

local cas = game:GetService("ContextActionService")

local function onXKeyPressed()
	print("X key pressed!")
end

cas:BindAction("XKey", onXKeyPressed, false, Enum.KeyCode.X)
cas:UnbindAction("XKey")

A solution has been provided but here’s the general gist of how this would be achieved (for those who were still unsure).