Step 7 of 8, updated

A Global

A Global is a system every script names with no use line, and the types it exports are bare everywhere.

You'll learn a Global with a type, the Global property, and using it with no use.

A global

Money starts as a system like the others. In Shot, insert a ModuleScript named Money and mark it as ShotScript:

ReplicatedStorage/Shot/Money.shot
system script

export Amount

«A number of coins.»
system type Amount = number

local SUFFIX = " coins"

module Money = {
	function Text(amount : Amount) : string
		return tostring(amount) .. SUFFIX
	end
}

return Money
  • Money has no RunContext set, so it is shared code: both sides may name it.

The global property

In ShotScript Editor's Properties, set Money's Global property to true.

  • With Global set, Money's values and exported types are bare in every script: no use, no import.
  • export Amount makes Amount a bare type in every script of the place.

Watch out A folder doesn't make a Global. A system in a folder named Globals is not a Global unless its system script's Global property is set to true.

Using it

The Client names Money with no use line:

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

local Players = game:GetService("Players")

print(Players.LocalPlayer.Name, "starts with", Money.Text(0))
print(Hud.Line(10))

And the Server types its start amount as Amount:

ServerScriptService/Server.shot
use game.ReplicatedStorage.Shot.Wallet

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player : Player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	local coins = Instance.new("IntValue")
	coins.Name		= "Coins"
	coins.Parent	= stats
	stats.Parent	= player
	local start : Amount = 10
	Wallet.Give(player, start, "Pickup")
end)