Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Bind multiple Keys with ContextActionService?

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 :)

1 comment

0

Line 14 is wrong. You’re checking if the player’s name equals "CrispyBrix", but also checking if the string "CowsBell" equals true.

1 answer

###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

1 comment

0

Sorry I have one as onleypressed and one as ondevpressed are those not two different names? Or am i missing something?

This discussion is preserved as it was. New answers, comments, and votes are closed.