Say which system starts first, and ShotScript Editor keeps the order
ShotScript

Say which system starts first, and ShotScript Editor keeps the order

By ShotScript Team4 min

A lot of Roblox games start from one server script. Each system has a Start function, and the script calls them one per line. The order of those lines is a rule that only lives in somebody's head. Move two of them during a cleanup and the game still starts, the Output stays clean, and something quietly stops working.

A ShotScript module can write that order down on its Start's own header line, and ShotScript Editor holds the start script to it.

A tycoon with four systems

We worked in a place with a Shot folder in ReplicatedStorage. Our example is a small tycoon, and each of its systems is a Folder there holding one ModuleScript of the same name. Each of those starts with the line system script, which makes it a system of its own, and ends by returning its module. Plots finds the plots players build on. Droppers puts a free starter dropper on every plot. Config loads the price multiplier, and Upgrades builds the price list from it. In ServerScriptService a Boot Script named Server starts all four:

ServerScriptService/Server.shot
-- Starts the game's systems

use game.ReplicatedStorage.Shot.Plots.Plots
use game.ReplicatedStorage.Shot.Config.Config
use game.ReplicatedStorage.Shot.Droppers.Droppers
use game.ReplicatedStorage.Shot.Upgrades.Upgrades

Plots.Start()
Config.Start()
Droppers.Start()
Upgrades.Start()

Two of those lines lean on the ones above them. Droppers walks over the plots, so they have to exist first:

ReplicatedStorage/Shot/Droppers/Droppers.shot
	«Puts a starter dropper on every plot»
	function Start()
		for _, plot in Plots.All() do
			table.insert(droppers, plot.Name)
		end
	end

And Upgrades multiplies by whatever Config has loaded, which is 0 until Config starts:

ReplicatedStorage/Shot/Upgrades/Upgrades.shot
prices.Dropper = 200 * Config.Multiplier()

The swap nobody hears about

Then we moved the lines around, Droppers and Upgrades first, Plots and Config after them:

ServerScriptService/Server.shot
Droppers.Start()
Upgrades.Start()
Plots.Start()
Config.Start()

The editor marks nothing, and every script compiles. Each call goes to a real function with the right arguments, so as far as the types can tell, nothing is wrong. In a game, Droppers would walk an empty list of plots and nobody would get a starter dropper, and Upgrades would multiply by 0 and every dropper would be free. Unless you happen to be watching for those two things, you'd hear about it from players.

One clause on the header line

Droppers needs Plots to start first, so its Start says so:

ReplicatedStorage/Shot/Droppers/Droppers.shot
	function Start() after Plots.Start «it puts a starter dropper on every plot; started first, it finds no plots and nobody gets one»

A clause can also point the other way. The multiplier belongs to Config, and whoever changes Config should see that Upgrades depends on it, so we put that rule on Config's side with before:

ReplicatedStorage/Shot/Config/Config.shot
	function Start() before Upgrades.Start «Upgrades prices every upgrade with this multiplier; started after, droppers cost 0»

The part in « » is optional. It's the reason, written for whoever touches the start script next, and the editor quotes it back to them word for word. Write it as what breaks when the order is lost.

With the two clauses in, the same swap gets two marks in Server, on lines 8 and 11. The one on line 8 starts like this:

Droppers.Start() runs before Plots.Start() (line 10), but Droppers.Start must run after it

Then it names the line in Droppers that holds the clause, quotes the clause with its reason, and offers three ways out:

move this line below line 10; or, to keep this order, make Droppers.Start do that without Plots.Start (when it is first needed, not at start), then drop after Plots.Start there; or if Droppers no longer needs that order, drop after Plots.Start there

The mark on line 11 has the same shape for Config. It starts Config.Start() runs after Upgrades.Start() (line 9), but Config.Start must run before it, and its first way out is move this line above line 9.

Each mark sits on the line that has to move and says where to move it. Then it offers two more ways out. If you want to keep the new order, Droppers could do its work without Plots at start, at the moment a plot first needs a dropper, and the clause goes. And if Droppers doesn't need the order any more, you drop the clause. That middle option is often the better design, and it's nice to have it suggested at the exact moment you're tempted to shuffle lines.

Without a reason the mark is shorter, and only the first and last ways out are offered:

move this line below line 10, or if Droppers no longer needs that order, drop after Plots.Start there

We moved both lines back, and the marks went away.

When the clause is the mistake

The editor reads the clauses as well as the start script. We broke ours three ways, and each time the mark went on the clause itself.

With a typo, after Plots.Strat, the mark on Droppers says no script calls Plots.Strat() (nearest: Plots.Start) and asks for the name as the start script calls it.

With Plots saying after Droppers.Start as well, the mark on Plots names both clauses and says they can't both hold: each wants its Start first. Keep the one that is still true and drop the other.

With Droppers.Start() moved out of Server into a second Boot Script, Starters, the mark on Droppers names where each Start is called, then says:

two scripts have no order between them, so after Plots.Start «it puts a starter dropper on every plot; started first, it finds no plots and nobody gets one» promises nothing. Drop it, or call both from one script

That one is worth knowing even if you never write a clause. Two server scripts in Roblox don't run in any order you can count on, so a Start that depends on another one has to be called from the same script.

What it won't find

The editor only knows the orders you declare. If two Starts depend on each other and nobody wrote a clause, it has no way to tell, and the start script can be in any order without a mark. Before you write a clause, try the swap on a copy and see whether anything changes. If nothing does, there's no order to declare.

Nothing at run time

The clause is for the editor only. When Droppers compiles, its Start comes out as a plain function:

	function Droppers.Start()
		for _, plot in Plots.All() do
			table.insert(droppers, plot.Name)
		end
	end

The clause stays in the copy of your source that the script keeps in a comment at the bottom, and nowhere in the code, so it costs the game nothing when it runs.