Skip to content

Server and client

When you play on a private server, three kinds of program are working together:

Program Runs Decides
The backend once, for the whole server accounts, what everyone owns, the store, contract progress, what’s on today (events, the daily shop)
A match server one per match or hideout, started by the backend what really happens in that match: hits, catches, KOs, scores
The game, a clientclient: A player's copy of the game. It runs the same scripts, and shows the player what the server decided. on every player’s computer what that player sees and hears, and their own movement

The backend and the match servers both come from the server install. The game is the client install. A private server’s host runs the first; every player runs the second.

When something has to happen once and everyone has to agree (a KO, a point, an item granted) the serverserver: The machine that runs the match and decides what really happened. Every player's game talks to it. decides and tells every game. The games show the result: the animation, the sound, the scoreboard changing.

Server
Each player's game
The ball hits a player: a KO
The same hit is seen locally
The server counts the KO
sent
The score arrives
The game plays the KO effect and sound
One hit, two halves: the server keeps score, each game shows it.

Sending values from the server to every game is called replicationreplication: The server sending a component's changed fields to every client, so they all agree.. Scripts choose which of their values are sent. See Replication if you’re scripting.

The server and the games read the same kinds of files, and they have to agree on them. A level the server spawns has to exist in every game, and a script the server runs has to be the same script the games run.

So a mod usually has files on both sides, and the two have to match. If the server places a prop the games have never heard of, or a game has a changed level the server doesn’t, the result is broken in ways that are very hard to trace back: players see things that aren’t there, or walk into things they can’t see.

Studio takes care of this. When you test, it installs your mod into both halves together, and works out for each file which side needs it. When you ship, it exports both halves at once. See Testing.

You’re changing Which side matters
A level, a prop, a model Both: the server spawns it, the games draw it.
A texture, a sound, an effect The games draw and play it; the server only needs to know it exists.
A price, an offer, a contract, a reward The server (backend).
A script Both: the same script runs on the server and in every game.

A script runs on the server and on every player’s game, at the same time. Most “works alone, breaks online” problems come from a script doing on one machine what it should do on another. The vscript guide has a page on exactly this: Server and client.

For programmers

An authoritative server model: the match server simulates the match and replicates chosen fields to clients, while each client simulates its own player’s movement locally. The backend is a separate service that owns accounts, inventory, the economy and schedules. One script runs everywhere; $net.is_server() tells a copy which side it’s on.

The store: offers, currencies, and what players can buy.