Learning script format

Script Format

What format is best to use when scripting? There are many ways and formats you can use to script but I’m not sure how to and which one to use. Any information you have on this topic, please inform me! I’m new to scripting and hope to become a good programmer.

What do you mean by script format?

um, what do you mean by formats? do you mean programming languages? Roblox only has one language, called Luau

like the order each line should be written in. Like if your making a script, what should you script first?

1 Like

Well, this is how I usually organize my scripts:

Variables:

Functions:

Other:

Connections:

2 Likes

No, I mean like the order you write. So if you are making an explosion, what would you write first? A function?

You should first script variables you need for the script. Then functions and then events (such as game.Players.PlayerAdded)

Tip: If you get a reply and you think its a solution, then mark it as a solution. (Im telling you this because i saw you make multiple topics which don’t have a solution)

If your making a script such as a kill brick then you would script in this format:

local KillBrick = game.Workspace:WaitForChild("KillBrick") -- We use waitforchild because the Killbrick could've not been loaded by the time this script runs. 

KillBrick.Touched:Connect(function(Touch)
   if Touch.Parent:FindFirstChild("Humanoid") then
      Touch.Parent.Humanoid.Health = 0
  end
end)

It’s preference? But uh, this is how I do it

Services

Variables

Constants

Functions

Connections

Other

Exporting (Module Scripts)

it’s better to use FindFirstChildOfClass or FindFirstChildWhichIsA

those two will look for the class type while FindFirstChild only checks the name

I would consider services as variables

Also, how do you make constants? Is it a luau feature?

No, it’s styling, a constant means its value cannot ever change.

// JS Example
const something = 123

-- Luau example, notice how it's a variable that just uses UPPER_SNAKE_CASE
local MY_CONSTANT_VAR = 123

MY_CONSTANT_VAR = 144

-- I can change the var, but by styling it as a constant, I tell other developers that you should not do this

I know it means that it will never change. Im just wondering if its possible to do it in lua

1 Like

Short answer: No. It’s styling, and it doesn’t matter,

honestly ur right but if you are scripting by yourself it doesn’t matter what you name it

1 Like