Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Difference In Connecting Functions?

Asked by 6 years ago

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
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 User#20388 0 — 6y
0
Ah ok. Thanks mate. NoahsRebels 99 — 6y

1 answer

Log in to vote
-1
Answered by
3ora 54
6 years ago

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.

1
Incorrect. This is a terrible answer. User#25115 0 — 6y
0
How? 3ora 54 — 6y
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. User#24403 69 — 6y
0
Thats what I meant. you could of just pointed out that I said "Lua" instead of Roblox API 3ora 54 — 6y
Ad

Answer this question