2 functions on 1 connect, How?

How would I do 1 Connect in 2 functions???

What it is right now:

uis.InputBegan:Connect(function(input)

What I want:

uis.InputBegan or Button.Activated:Connect(function(input)

Is this possible? (Btw the code above does not work but you probably understand what I’m trying to do)

What exactly are you trying to achieve with tying two functions to an event?

Because either approach it with:

A: Hooking function 1 to the event and then firing function 2 as first line within function 1
B:

Button.Activated:Connect(function()
   function1()
   function2()
end

here’s what you do:

Have one function and connect both events to that function

local function doWhatEverYouWant(input : InputObject)
	print(input.KeyCode)
end

uis.InputBegan:Connect(doWhatEverYouWant)
button.Activated:Connect(doWhatEverYouWant)
1 Like

but how would i tell if it was the button that was pressed?

Maybe;

local function doWhatEverYouWant(input : InputObject)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("Button clicked")
    elseif input.UserInputType == Enum.UserInputType.Keyboard then
        print(input.KeyCode)
    end
end

uis.InputBegan:Connect(doWhatEverYouWant)
button.Activated:Connect(doWhatEverYouWant)

Guess you would only need that fist check to know it was the mouse…

does mousebutton1 also detect mobile players pressing the button?

(Dosent work btw)

mousebutton1click can detect mobile players ( wait i dont think i understand )

Why do you even need Activated if you’re using InputBegan, nevermind talking about the question in the title (this is an XY problem)? InputBegan will fire when any input method is used to interact with the GuiObject whether it is mouse, touch or anything else.

local function doWhatEverYouWant(yes : boolean)
    if yes then
        print("Button clicked")
    else
        print(input.KeyCode)
    end
end

uis.InputBegan:Connect(function()
 doWhatEverYouWant(false)
end)

button.Activated:Connect(function()
 doWhatEverYouWant(true)
end)

it doesn’t know what input is

and I’m gonna try doing solutions and ill update if i figure it out

the variable will change depending on the input type

It gives an error saying its nil

I hope I’m not invisible to you - see the message I’m replying to for my initial advice. Whatever you’re trying to do, you don’t need to do it. Not only is it not possible but InputBegan can already take care of this alone. You’re unnecessarily complicating this for yourself.

Probably wants a keyboard shortcut for something like a menu + a gui button to directly access it, which mobile users can use too.

Oh, yeah I see it now, OP is using UserInputService’s version of InputBegan rather than the GuiObject’s version. That would require two separate connections.

HeCatchThose’s reply has it down.

local function doWhatEverYouWant(input, yes : boolean)
    if yes then
        print("Button clicked")
    else
        print(input.KeyCode)
    end
end


uis.InputBegan:Connect(function(input)
 doWhatEverYouWant(input, false)
end)

button.Activated:Connect(function()
 doWhatEverYouWant(nil, true)
end)

theres Probably a better way but i am too busy to think.

I am assuming the issue was that input was nil because the parameter was not passed through.

yet another error, im not sure if its because im doing input.KeyCode? cause thats what im trying to do as i want it to do something when E is pressed and not something else

Actually correction: i didn’t see the extra parameters sorry

1 Like