Hey all, Merry Christmas to those of you that celebrate it. I'm writing a chunky code, and I have a single function that 4 events will trigger. Each of these 4 events takes up a line of code, which eventually adds up later. How would I enforce DRY (Don't Repeat Yourself) on such a block?
local function Click() print("Do Stuff") end Button1.Activated:Connect(Click) Button2.Activated:Connect(Click) Button3.Activated:Connect(Click) Button4.Activated:Connect(Click)
I can clearly see that you're using the wrong event/trigger. This is a UI object, am I right? If so, the click is detected by doing MouseButton1Click.
local function Click() print("Do Stuff") end Button1.MouseButton1Click:Connect(Click) Button2.MouseButton1Click:Connect(Click) Button3.MouseButton1Click:Connect(Click) Button4.MouseButton1Click:Connect(Click)
Also, please make sure that Button1, Button2, etc are variables, if they are not, you can declare a variable by doing this:
local Button1 = script.Parent