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

Point of putting function() inside brackets after connect?

For example

script.Parent.MouseButton1Click:Connect(Function(Click)

6 comments

1

You should look up anonymous functions in lua

0

Explain your question please. I didn't get it.

0

err.

0

The function Connect needs a function to be passed as the first argument

0

I think he wanted to say parameters :/

1 answer

✓ Accepted answer

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

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