Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I disable keys in the actual game?

Asked by 5 years ago

Hi!

I was trying to make a script for a 2D platformer that disables the 'w' and 's' keys, and replaces the action 'w' performs with 'jumpAction'. Here is the code (in a localScript):

local ContextActionService = game:GetService("ContextActionService")
local plyr = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")

for _, controller in pairs(game:GetService("ControllerService"):GetChildren()) do
    controller:Destroy()
end

uis.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.W then
        if plyr.Character:FindFirstChild("Humanoid") then
            plyr.Character.Humanoid.Jump = true
        end
    end
end)
ContextActionService:UnbindAction("forwardMovement")
ContextActionService:UnbindAction("backwardMovement")
ContextActionService:UnbindAction("jumpAction")

For some reason, the code only works in the editor, and not the actual game. Can someone explain what I'm doing wrong? Thanks

0
ContextActionService:UnbindAllActions() User#19524 175 — 5y
0
Thx so much :) MyNameIsPhip 0 — 5y

Answer this question