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

How do I do multiple keybinds?

So I want to make this program but when there are two of them running at the same time, none of them works. Also, if you don't mind, can you explain me how this code works?

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		script.Parent.YAAA:FireServer()
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)


function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		script.Parent.Fire:FireServer()
	end
end
 
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)

1 answer

✓ Accepted answer

Try this

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

Or this

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        script.Parent.YAAA:FireServer()
    end
end

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


function onKeyPressT(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        script.Parent.Fire:FireServer()
    end
end

game.ContextActionService:BindAction("keyPress2", onKeyPressT, false, Enum.KeyCode.E)

4 comments

0

This didn't work, it only binds to the 2nd function I want each of them to have their own function

0

Have you tried the seccond solution

0

Thank you

0

If this questions answers the issue @superbolt999 can you mark this question as the answer?

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