its because lua can get complicated at times
like how using table + table is not possible unless metamethod __add is found and used correctly
so lets explain in parts:
game.Players.PlayerAdded
this part is to target the event we will be using
:connect()
this is a method that actually "connects" the event with our function
now what is inside the () is a single parameter: the function
we could automatically set it to a predefined function:
local function OnTouch(hit)
hit:GiveLoveAndSupport()
end
Part.Touched:connect(OnTouch)
however, most would rather create a function within the (), to do something like this, we would do this simply with:
(function(parameter, otherparameters) code here end)
and so we do this within :connect()
now parameters within the function() are given to the function by :connect()
i dont exactly know how it would do this, but i could imagine it going like this:
thing:connect = function(functiontouse)
functiontouse(thingwegotearlier)
end
and how lua deals with this is that we give parameters to the defined function respectivly:
function foo(a)
print(a .. "!")
end
doo:connect(foo)
:connect gives out parameters: "doo"
so foo runs like:
foo(doo)
so we would get
doo!
1 comment
:connect is deprecated plz