Skip to content

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_server is true
  • mod.save, mod.weapons.on_plan, weapon_fire
Client VMThe screen. Drawing, input, sound, the HUD. One per player.
  • mod.is_client is true
  • mod.ui, mod.fx, mod.audio, mod.game.cash
  • Data changes need no thought. Data files and mod.data calls apply in both VMs, so both agree on prices, HP and rules.
  • main.luau runs 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_landed fires in both; weapon_fire and save_loaded only on the server; frame and ui_open only on the client. See the events table.

For a whole file, return early:

main.luau
-- mod.save lives in the server VM. The client keeps nothing between sessions.
if not mod.is_server then
return
end

For one block, check inside the handler. Solar Flare does both halves of a hit in one handler:

main.luau
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)
end
end)

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.