Two VMs
The game runs as two Luau VMs that talk over a network link, even in single player:
Server VMThe rules. Islands, missiles, bots, superweapons, cash, saves. One per game: on your machine in single player, on the host’s in co-op.
mod.is_serveristruemod.save,mod.weapons.on_plan,weapon_fire
Client VMThe screen. Drawing, input, sound, the HUD. One per player.
mod.is_clientistruemod.ui,mod.fx,mod.audio,mod.game.cash
your main.luau runs in both
What that means for your mod
Section titled “What that means for your mod”- Data changes need no thought. Data files and
mod.datacalls apply in both VMs, so both agree on prices, HP and rules. main.luauruns twice, once per VM, with its own variables. A counter in one VM is not the counter in the other.- Calls belong to one side. On the wrong side, most of them do nothing instead of failing, so a handler that runs in both is safe. Each call’s page in the API reference shows its side as server + client, server or client.
- Events say where they fire.
weapon_landedfires in both;weapon_fireandsave_loadedonly on the server;frameandui_openonly on the client. See the events table.
Picking a side
Section titled “Picking a side”For a whole file, return early:
-- mod.save lives in the server VM. The client keeps nothing between sessions.if not mod.is_server then returnendFor one block, check inside the handler. Solar Flare does both halves of a hit in one handler:
mod.on("weapon_landed", function(e) if e.weapon ~= "solarflare" then return end flares += 1 if mod.is_server then -- the server keeps a lifetime total in the save file local total = (mod.save.get("total") or 0) + 1 mod.save.set("total", total) mod.game.toast(mod.text("flare.landed", total)) else -- the client shows it: a white flash and a shake (both respect the player's -- "reduce motion" and shake settings) mod.fx.flash(0.5, 0.25) mod.fx.shake(5) endend)In co-op
Section titled “In co-op”The host runs the server VM and its own client. Every other player runs only a client. So:
- server code runs once per game, on the host;
- client code runs on every player’s machine;
- a toast from the server reaches everyone, a toast from a client only that player.
That is why every player needs the same mods: their client VMs run your client code. Saves and co-op has the check the host does.