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

Point of putting function() inside brackets after connect?

Asked by 5 years ago

For example

script.Parent.MouseButton1Click:Connect(Function(Click)
1
You should look up anonymous functions in lua Impacthills 223 — 5y
0
Explain your question please. I didn't get it. vBaRaAx02 1 — 5y
0
err. Zafirua 1348 — 5y
0
The function Connect needs a function to be passed as the first argument User#5423 17 — 5y
View all comments (2 more)
0
I think he wanted to say parameters :/ mewant_taco 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I will explain you why, for example:

script.Parent.MouseButton1Click:Connct(function(what does function receive from the connect function) 'function code here' end)

as you see, any function uses these brackets to contain some different values depending on what the function sends and receives, for example: using " function functionName() " we use brackets to get values, just look in this code

local function MyFunction(plr)
    print(plr.Name) --This will print the name of the clicker
end)

script.Parent.Changed:MyFunction(Clicker)

as you see it sent a value with a name of "Clicker" but it received it as "plr", because it doesn't send the name of the value, it only sends the value, so how will you use it like this:

local function MyFunction plr
    print(plr.Name) --This will print the name of the clicker
end)

script.Parent.Changed:MyFunction Clicker

it won't work, because it won't detect which is the code, and which are the values received, so () are used to contain values you can't use the connect function like this

script.Parent.Changed:Connect function()
    print('Hi!')
end

print('This text is printed out from the connect function')

How will the game detect which codes are not a part of the connect function and which codes are in the connect function

Ad

Answer this question