Shared code
A module in ReplicatedStorage is code both sides can use. use brings it into a script.
You'll learn a module declaration, the return at its bottom, and use with a path.
A module
In ReplicatedStorage, make a Folder named Shot, insert a ModuleScript named Format in it, and mark it as ShotScript. The mark writes system script as its first line, so Format is a system of its own.
The table is the declaration, and its functions are written inside it:
--!strictlocal SUFFIX = " coins"local Format = {}function Format.Coins(amount: number): string return tostring(amount) .. SUFFIXendreturn Format
system scriptlocal SUFFIX = " coins"module Format = { function Coins(amount : number) : string return tostring(amount) .. SUFFIX end}return Format
- Plain Luau above the declaration is kept as it is: services, requires, constants, local functions.
--!strictis implied, so you don't write it. ShotScript Editor writes Format's Source by itself, with your text kept in a comment block.return Formatat the bottom says what the script hands out. The mark wrote it, renaming Studio'sreturn module.FormatModuleis Format's type, so every script that uses Format sees the real signature ofCoins.
Watch out A script with no return at the bottom is a blank, which hands out nothing. Every script that hands something out ends with its return, a system script (the next step) too.
Using it
A script outside Shot reaches Format by its path from game. The Client uses Format:
use game.ReplicatedStorage.Shot.Format local Players = game:GetService("Players") print(Players.LocalPlayer.Name, "starts with", Format.Coins(0))
usebrings Format in. It stands for arequire, and a path fromgamestays rooted atgame, so the script finds Format wherever it is cloned:
local Format = require(game:GetService("ReplicatedStorage").Shot.Format)
- Format has no side, so the server could use it too.
Tip A bare use Format, with no path, finds the nearest Format: the script's own children first, then its folder, then each folder up. Scripts inside Shot use it that way in the next steps.
