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)
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…
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)
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.
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.
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