The function above prints “Button Clicked” when the button is clicked, obviously.
But as I was learning more about functions I saw something like this:
local button = game.StarterGui.ScreenGui.TextButton
local function ButtonClicked()
print("Button Clicked!")
end
button.MouseButton1Click:Connect(ButtonClicked)
My question is, the button.MouseButton1Click:Connect(ButtonClicked) runs the function, right? Also if I duplicate it will it run multiple times? Like this:
local button = game.StarterGui.ScreenGui.TextButton
local function ButtonClicked()
print("Button Clicked!")
end
button.MouseButton1Click:Connect(ButtonClicked)
button.MouseButton1Click:Connect(ButtonClicked)
button.MouseButton1Click:Connect(ButtonClicked)
-- Prints "Button Clicked!" x3
Also another thing, so lets say a looped function or a connected one many times it will print something like:
-- "Printed statement" x7
So if I print it it will have a number saying however many times it was printed. Now if we print different strings multiple times what will the output be like?
For instance:
Print("A")
Print("B")
Print("C")
Print("D")
-- Pretend the prints above are in a function that ran twice
Would the output be:
-- "A" "B" "C" "D" x2
-- or
-- "A" "B" "C" "D" "A" "B" "C" "D"