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 enabled | runs on the client |
@server enabled | runs on the server |
@client disabled | the same with Enabled off, for something else to turn on |
@server disabled | the 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
enabledordisabled("@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
@clientscript can't require a server module, a@serverscript 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.
