Short answer: No
While you canβt detect events like that, you could connect them to the same function so only a single function deals with them both:
for _,button in pairs(script.Parent:GetChildren()) do
if button:IsA('TextButton') then
button.MouseButton1Click:Connect(function()
print(button)
end)
end
end
This can be achieved by connecting the same callback function to two or more event objects via the event connection instance method β:Connect()β, for the first example that would look like.
local Players = game:GetService("Players")
local function PlayerCountChanged()
print("Number of players: "..#Players:GetPlayers())
end
Players.PlayerAdded:Connect(PlayerCountChanged)
Players.PlayerRemoving:Connect(PlayerCountChanged)
and for the second example.
local frame = script.Parent
local button1 = frame:WaitForChild("Button1")
local button2 = frame:WaitForChild("Button2")
local function onButtonPressed()
print("Button pressed!")
end
button1.MouseButton1Click:Connect(onButtonPressed)
button2.MouseButton2Click:Connect(onButtonPressed)