Is there a UserInputType for .Button.Activated?

I am trying to use ContextActionService to bind several inputs.

Buttons have an event called Activated.

But, when I look at UserInputType I don’t see “Button” or “Activated” as an options.

Here is an example of what I want:

ContextActionService:BindAction("BindOne", FunctionOne, false, Enum.KeyCode.One, Enum.UserInputType.ButtonOne.Activated)

But, there is no such thing as .Button.Activated for UserInputType.

I see MouseButton1 or Touch but not a combined event like Activated.

Does anyone know how to bind a button and a keyboard input to the same function?

Couldn’t you use InputBegan? It should be the same aside from having to make multiple if statements for the same function.

1 Like

Can’t you just make a connection outside of the binding to the function?

ContextActionService:BindAction("BindOne", FunctionOne, false, Enum.KeyCode.One, --[[any other inputs to bind]])
Button1.MouseButton1Click:Connect(FunctionOne) --or any other event

I can, but the idea is to have one action that binds and unbinds.

Just disconnect the connection when unbinding, or make the button invisible. I don’t think there’s a way to add GUI object events to a ContextActionService bind.

Someone please correct me if I’m wrong, I’m not 100% sure.

I think I will just not worry about it.

I was reading the docs on connecting / disconnecting functions.

It looks like there is no reason to connect / disconnect unless you just don’t want the function to run the next time the button or quick key is pressed.

It says all player connections are removed when the player leaves the game. And, it doesn’t say that a new connection is made every time the player presses a button or a quick key. (My area of misunderstanding.)

The connection is only established one time and it kept open until deliberately disconnected.

Correct me if I’m misunderstanding again.

Connect functions when you need, disconnect them when you don’t need. ALWAYS disconnect functions when you don’t need them anymore, exept only 2 cases:
Instance which did connection destroyed
Connection should be permanent.

Otherwise, every connected function will consume memory, cause lags, and will be memory leak reason.

The documentation says nothing about memory leaks.

It only makes one mention of disconnecting functions:

If you connect a function to an event but don’t want the function called in subsequent event firings, disconnect it from the event by calling Disconnect()

Documentation doesn’t mention every detail. Not disconnected functions are one of the most common mistakes and memory leak issues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.