Step 3 of 8, updated

A server script

The second script runs on the server. It gives every player a Coins stat.

You'll learn a server script, typed code, and what happens to a mistake.

The script

In ServerScriptService, insert a Script named Server, set its RunContext to Server, and mark it as ShotScript:

ServerScriptService/Server.shot
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
end)
  • Its side is its RunContext: Server.
  • player : Player types the parameter, so everything the function does with player is checked.
  • Every script is checked in strict mode. --!strict is implied, so you don't write it.

A mistake

Try it

Add coins.Value = "ten" above coins.Parent = stats. The editor marks that line as you type: Value holds a number, not a string.

Watch out A script that doesn't compile is refused. The editor says Not compiled: <reason> (line N). This script errors in Play until it compiles. Play stops at that script until you fix the line.