Setting Up Connections

Small Questions I have on Setting up Connections (or Events), However, this question may just be up to Personal Prefrence so I’m not sure.

But what would be the better way of doing this, so for Example, I have a Part that when touched, will do something, should I set it up like this:

BasePart.Touched:Connect(function(otherPart)
    print(otherPart)
end)

or like this:

function OnTouch(otherPart)
    print(otherPart)
end

BasePart.Touched:Connect(OnTouch)

But Again, this just may be up to Personal Prefrence, So not sure.
But what should I be doing?

If you use a function multiple times, make a function for it with the second preference
If only once, create the function as you connect it with first preference

Personally I like the first one:

BasePart.Touched:Connect(function(otherPart)
    print(otherPart)
end)

because i easily understand what functions are inside that functions such as:

Players.PlayerAdded:Connect(function(plr)
   plr.CharacterAdded:Connect(function)
   end)
end)

Again, its’s up to preference and your choice. there is not much of a difference in general such as perfomance or anything that affects game-wise

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.