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

I have a question about functions. Can someone help me?

Hello! So I was reading about functions, but I an still kinda confused why people add this () at the end of code lines for an example,

local re = game.ReplicatedStorage:WaitForChild(OnFireballThrown)

local mouse = game.Players.LocalPlayers:GetMouse()

I am confused on why that () is there because that defiantly doesn’t mean OnFireballThrown so what does that mean?

3 comments

0

They are called arguments and parameters. I think you should watch a tutorial on them on YouTube regarding roblox.

0

nil

0

They are used for parameters and arguments and you fill them in with strings if you need to use them otherwise leave them blank. Here is a tutorial: https://www.youtube.com/watch?v=bkp3OBs0oV0&t=2s

1 answer

() is for parameters or built in variables in events. What I mean by this is,

local function x(a,b,c)
	print(a,b,c)
end
print(x('hi','hi2','bruh'))

Expected output: hi, hi2, bruh

Functions by default have to end in () unless it's in an event:

workspace.Part.Touched:Connect(functionName)

In this situation the variables are transferred to functionName. This might be confusing so I'll show it another way:

local function functionName(ThingThatWasTouched)
	print(ThingThatWasTouched.Name)
end
workspace.Part.Touched:Connect(function(TheThingThatWasTouchedBeingTransferred)
	functionName(TheThingThatWasTouchedBeingTransferred)
end)

Hope this makes sense, if it doesn't then lmk in comments

2 comments

0

Ok so basically if if it’s a function then it has to end with a () right? Also how do you know if something is a ‘function name’

0

functionName is like a variable, you can name it everything but it has to be setup like that, you can ignore "ThingThatWasTouched", functionName() can be renamed to anything basically

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