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

What is the point of a function? What does it do? Do you need them?

I think I know what they are, I just want to make sure. Plus this may help others!!!

1 answer

✓ Accepted answer

A function is a chunk of code that you encase that will only run when called on. for instace

--this is how you make a function with the name 'printSomeLines'
function printSomeLines()
	print('hello')
	print('World')
end

The code in this function will only run if the function is called upon like so

--since we already created the function above doing this will run all of the code inside of it
printSomeLines()

Alot of events in this game allow you to connect a function to it when they trigger like

--This connected function will run whenever the button is clicked
button.ClickDetector.MouseClick:Connect(printSomeLines)

However, you dont have to create your own function and call it, you can make an anonymous function and put it in the event like so

button.ClickDetector.MouseClick:Connect(function()
	print('Hello')
	print('World')
end)

3 comments

0

Yep, super helpful! Use em all over the place haha

0

yes functions store code which can be used in the future

0

hey, I wrote the first answer on this question, sorry it was really bad and not helpful, I was in a rush and just tried to help, I know the answer sucked.

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