Which is better to use?

So I am wondering which is better to use, option 1 or option 2 is one better than another in certain situations?

local button = script.Parent.ClickDetector

--Option 1
button.MouseClick:Connect(function()
	print("Button pressed")
end)
--Option 2
local function buttonPressed()
	print("ButtonPressed")
end

button.MouseClick:Connect(buttonPressed)

I always use option 1.

1 Like

It’s fairly better if you do it in an organized matter, but the choice is really yours. These are both the same.

Option 2

1 Like

I think it’s more of an organization thing that doesn’t have much of an effect on performance and it doesn’t really matter which you use.

I see what you mean, i usually use option one because its shorter.

Option one is better if your only making that same connection on one object.
Ex.

workspace.Part.Touched:Connect(function()
print("i was touched")
end)

Option two is generally better if you need to connect two events to the same function.

function hit()
print("i was touched")
end

workspace.Part.Touched:Connect(hit)
script.Parent.TextButton.MouseButton1Down:Connect(hit)

The same thing can be said for coroutines, or practically anything that takes a function as an argument.
Its mostly up to preference though.

I see, i never thought there was a point in using option 2 other than for organization. Thank you.