Step 4 of 8, updated

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:

struck ShotScript writes it for youhighlighted new in ShotScript
ReplicatedStorage/Shot/Format.luau
--!strictlocal SUFFIX = " coins"local Format = {}function Format.Coins(amount: number): string	return tostring(amount) .. SUFFIXendreturn Format
ReplicatedStorage/Shot/Format.shot
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.
  • --!strict is implied, so you don't write it. ShotScript Editor writes Format's Source by itself, with your text kept in a comment block.
  • return Format at the bottom says what the script hands out. The mark wrote it, renaming Studio's return module.
  • FormatModule is Format's type, so every script that uses Format sees the real signature of Coins.

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:

StarterPlayer/StarterPlayerScripts/Client.shot
use game.ReplicatedStorage.Shot.Format

local Players = game:GetService("Players")

print(Players.LocalPlayer.Name, "starts with", Format.Coins(0))
  • use brings Format in. It stands for a require, and a path from game stays rooted at game, so the script finds Format wherever it is cloned:
StarterPlayer/StarterPlayerScripts/Client.luau
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.