Scripts

Put @client or @server on the first line of a file and it runs by itself when the game starts, like the two Init scripts every project has.

Classes, modules and funcs only run when something requires them. A script is the file that runs on its own: it compiles to a Roblox Script, and the two in Init require your systems and start them.

A script

Init/Server.shot

@server enabled

local Bank = require(@shot.Wallet.Bank)
local Market = require(@shot.Market)

Bank.Start()
Market.Server.Start()

A .shot file whose first line is @client or @server is a script. It compiles to a Script with its RunContext set to Client or Server, runs on its own when the game starts, and returns nothing.

@client enabledruns on the client
@server enabledruns on the server
@client disabledthe same with Enabled off, for something else to turn on
@server disabledthe same on the server, with Enabled off
  • The line must be the very first line ("@server goes on the first line of the file") and needs enabled or disabled ("@client needs enabled or disabled after it: @client enabled").
  • A script has no types line and declares nothing. Declaring something is an error ("Runner.shot is a @client script: a script runs and returns nothing, so it can't declare a class").
  • Nothing can require a script ("Client is a @client script (Init/Client.shot): a script can't be required").
  • It follows the rules of its side: a @client script can't require a server module, a @server script can't require a client one (see Server and client).
  • Without a types line, a script sees no Shot types by their bare names. Reach them through the module it requires: a system's entry point re-exports the system's public types.
local Wallet = require(@shot.Wallet)

local wallet : Wallet.Wallet = Wallet.new(0)

Init

Every project has a folder Init with two scripts:

Init/Client.shot@client enabled
Init/Server.shot@server enabled

Their job is to start the game: require the systems and call their start functions, in order.