Hi, I need advice on how to start a code that handles player controls
For say:
I need this code to block the movement keys (W, S)
But I don’t know how to start the code I tried to make one but in the end it turned out that I still didn’t know how to do it. I’m new to code issues. I’m waiting for your advice to help me start the code and where to put this code.
I already tried to make several codes but none works well and for the game I am creating I need to lock some keys
I appreciate your help since I am new to roblox studio
sorry if you do not understand several things my English is not very good
If you want to block specific keys (W and S like said in your example) then you can use ContextActionService:BindActionAtPriority to block those keys until you unbind it again.
local CAS = game:GetService("ContextActionService")
local KeysToBlock = {
Enum.KeyCode.W,
Enum.KeyCode.S
}
function BlockKey()
return Enum.ContextActionResult.Sink
end
local function Block()
CAS:BindActionAtPriority("BlockKeys", BlockKey, false, Enum.ContextActionPriority.High.Value, table.unpack(KeysToBlock))
end
local function Unblock()
CAS:UnbindAction("BlockKeys")
end
Calling Block() would block all Keys that are in the KeysToBlock table, and calling Unblock() would free them again. If you want to execute code instead of just blocking them, then refer to ContextActionService | Documentation - Roblox Creator Hub to learn on how to do that.