I have a few questions that I have at the back of my mind for a long time,
When do I put end to end a function?
How do I know when to put in a end?
What is different from this end to end) like this?
I sometimes add end but is quite annoying to test out when to put end in your script, I sometimes paste in a section of a script and the end doesn’t automatically be added.
do
-- block
end
if x then
end
while x do
end
for x do
end
function()
end
The only exception to this is the repeat until, those don’t use end.
This is just passing a function to another function, so the ) after the end is just closing off the function call.
f(function()
end)
f( function() end )
Functions are first-class values, so they are treated the same as values of any other datatype. They can be passed around to functions as arguments, they can be stored in variables, etc.
To actually understand when to put an end of a script, it is when you should exit the scope of the function; leaving the function environment. If you want certain variables outside the environment, just put them before the function, but it is usually unusual that a variable is written after functions.
Anything that incapaz mentioned is correct. The parenthesis isn’t much of a deal, it closes the existing parenthesis from the beginning.
If you Mess Up Adding an “end” In A Script it Will be Underlined Red So that you Know there Is An Error.
Normally Once you Open parenthesis The script will Automatically Add in an “end” or “end)” for you.
In Other Cases, You Can Just Check If You Closed a function Or Not.
Suppose You Make a function
game.Players.PlayerAdded:Connect(function()
Now, You Can See You Have Opened 1 Bracket After the “Connect” Word and Havent Closed It,
Hence You Know You Need to add an “end” with a Closing Bracket.