Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Difference In Connecting Functions?

I've been making some Touched scripts and wanted to know if there's a difference between connecting the function whenever the part is touched, because I've seen people do it two different ways.

The way I normally do it is:

function Test()
	print("Hello!")
end

script.Parent.Touched:Connect(Test)

But I've seen some other people use:

script.Parent.Touched:Connect(function(Test)
	print("Hello!")
end)

Is one way better to use then the other, or is it just used differently for cosmetic purposes?

2 comments

2

it really depends what your using it for, there is no real difference, at the second example your just putting the function between the parantheses instead of putting an already existing function there, it depends on your usecase, for example, if you need to call the function from multiple events it's better to do it with way 1, while if you only need it for e.g. a touched event 2 is good too

0

Ah ok. Thanks mate.

1 answer

It depends, if you are looking to create your own function and be a little more advanced, then use your way. If not, then you may use Roblox functions (in this case: "Touched").

The only difference is that your way is your own function and the second way is a function built into lua. They both do the exact same things in terms of functionality.

4 comments

1

Incorrect. This is a terrible answer.

0

How?

0

-1 for saying "The only difference is that your way is your own function and the second way is a function built into lua". Roblox API is what has Touched events and such. Test() isnt built into Lua either.

0

Thats what I meant. you could of just pointed out that I said "Lua" instead of Roblox API

This discussion is preserved as it was. New answers, comments, and votes are closed.