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

Bind multiple Keys with ContextActionService?

Asked by 5 years ago

So I had P binded to bring up a menu and it worked. But then I added another where N brings up a different menu and P stopped working. I tried googling it and found out that I had the same function name for both, so I fixed that but only one key works still?

local player = script.Parent.Parent
local ContextActionService = game:GetService("ContextActionService")

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        player.PlayerGui.Menu.Enabled = not player.PlayerGui.Menu.Enabled
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.P)

function onDevPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        if player.Name == "CrispyBrix" or "CowsBell" then
            player.PlayerGui.DevMen.Enabled = not player.PlayerGui.DevMen.Enabled
        end
    end
end

game.ContextActionService:BindAction("keyPress", onDevPress, false, Enum.KeyCode.N)

No errors or anything just the P does not work. Any help is appreciated :)

0
Line 14 is wrong. You’re checking if the player’s name equals "CrispyBrix", but also checking if the string "CowsBell" equals true. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

It doesn’t work because you are assigning the same name to a different function. Set a different name for one of them, and it should work.

I noticed a mistake on line 14, so I decided to fix it:

if player.Name == "CrispyBrix" or player.Name == "CowsBell" then
0
Sorry I have one as onleypressed and one as ondevpressed are those not two different names? Or am i missing something? CrispyBrix 113 — 5y
Ad

Answer this question