Skip to content
Back to skills

Roblox Luau

ASecurity

Use for any task that writes, fixes, moves or reviews Roblox Luau - placing scripts so they run, building remotes or a shop, saving player data, setting up a Rojo project, or replacing deprecated APIs in old or AI-generated code. Explains where code runs (Script, LocalScript, ModuleScript, RunContext, which container, and how Rojo maps .server.luau and .client.luau files), the client/server split and validating RemoteEvent arguments on the server, the task library instead of wait/spawn/delay,...

  • 3 stars
  • 0 votes
  • 1 copy
  • 4 views
  • Added November 29, 2026
ai-agentsrustgoangularapisecurity

Works with

  • cli
  • api
  • mcp

Security analysis

A100/100

Scanned December 1, 2026

npx -y skills add flxnsee/gamedev-toolkit --skill roblox-luau --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Roblox Luau?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Roblox Luau
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/flxnsee-roblox-luau/badge)](https://www.skillsdirectory.com/skills/flxnsee-roblox-luau)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: roblox-luau
description: Use for any task that writes, fixes, moves or reviews Roblox Luau - placing scripts so they run, building remotes or a shop, saving player data, setting up a Rojo project, or replacing deprecated APIs in old or AI-generated code. Explains where code runs (Script, LocalScript, ModuleScript, RunContext, which container, and how Rojo maps .server.luau and .client.luau files), the client/server split and validating RemoteEvent arguments on the server, the task library instead of wait/spawn/delay, workspace:Raycast and OverlapParams, mover constraints, Animator:LoadAnimation, data stores with pcall, UpdateAsync and BindToClose, and typed Luau with --!strict.
license: MIT
metadata:
  author: gamedev-toolkit
  version: "0.1.0"
---

# Roblox Luau

Roblox code runs in two places: the server (one per game instance, authoritative) and each
player's client (untrusted). Most bugs and exploits come from putting code on the wrong side
or trusting the client. After writing code, run the `roblox-luau-lint` skill if available.

## Where code runs

| Put it in | As | Runs on | For |
| --- | --- | --- | --- |
| ServerScriptService | Script (`*.server.luau`) | Server | Game logic, data, anti-cheat |
| ServerStorage | ModuleScript, assets | Server only (doesn't replicate) | Server modules, maps, templates |
| ReplicatedStorage | ModuleScript (`*.luau`), RemoteEvents | Required on both sides | Shared code, config, remotes |
| StarterPlayer > StarterPlayerScripts | LocalScript (`*.client.luau`) | Each client | Input, camera, UI controllers |
| StarterPlayer > StarterCharacterScripts | LocalScript or Script | Copied into each character | Per-character behavior |
| StarterGui | LocalScript inside ScreenGuis | Each client | UI |
| ReplicatedFirst | LocalScript | Each client, before anything else | Loading screens |

A legacy `Script` only runs in ServerScriptService or Workspace (characters and equipped
tools are in Workspace). A `LocalScript` only runs under a player (the Starter* containers
above, and ReplicatedFirst). A Script whose `RunContext` is `Server` or `Client` runs on that
side from other containers too. A ModuleScript runs once per side the first time it's
`require`d, and the server and each client get their own copy.

Everything in ReplicatedStorage, Workspace and the client containers can be read by
exploiters, including scripts that never run on the client. Keep secrets and server logic in
ServerScriptService and ServerStorage.

## Modern APIs (the deprecated ones still run, but don't write them)

| Don't | Do |
| --- | --- |
| `wait(t)`, `spawn(f)`, `delay(t, f)` | `task.wait(t)`, `task.spawn(f)`, `task.delay(t, f)`; also `task.defer`, `task.cancel` |
| `ypcall` | `pcall` (it can yield) |
| `workspace:FindPartOnRay(ray, ...)` | `workspace:Raycast(origin, direction, raycastParams)` |
| `FindPartsInRegion3*` | `workspace:GetPartBoundsInBox(cframe, size, overlapParams)`, `GetPartBoundsInRadius`, `GetPartsInPart` |
| `BodyVelocity`, `BodyPosition`, `BodyGyro` | `LinearVelocity`, `AlignPosition`, `AlignOrientation` (with Attachments) |
| `BodyForce`/`BodyThrust`, `BodyAngularVelocity`, `RocketPropulsion` | `VectorForce`, `AngularVelocity`, `LineForce` |
| `humanoid:LoadAnimation(anim)` | `humanoid:WaitForChild("Animator"):LoadAnimation(anim)` |
| `obj:Remove()`, `:connect()`, `:clone()`, `:findFirstChild()` | `obj:Destroy()`, `:Connect()`, `:Clone()`, `:FindFirstChild()` |
| `game.Players`, `game.Workspace` | `game:GetService("Players")`, `workspace` |
| `Instance.new("Part", parent)` | `Instance.new("Part")`, set properties, then `part.Parent = parent` last |
| `"Hi " .. name .. "!"` with many pieces | `` `Hi {name}!` `` (string interpolation) |

Signals: `:Connect(f)`, `:Once(f)` (disconnects itself), `:Wait()`. Keep the connection
(`local conn = signal:Connect(...)`) and call `conn:Disconnect()` when the object or feature
goes away. For timing, use `os.clock()`.

## Remotes and security

```lua
-- ReplicatedStorage/Remotes: a RemoteEvent named "BuyItem"
-- client (StarterPlayerScripts/shop.client.luau)
BuyItem:FireServer("sword")            -- never pass the player; the server gets it

-- server (ServerScriptService/shop.server.luau)
BuyItem.OnServerEvent:Connect(function(player: Player, itemId: unknown)
    if typeof(itemId) ~= "string" then return end          -- type check everything
    local item = Items[itemId]
    if not item then return end                            -- does it exist?
    if not canAfford(player, item.price) then return end   -- the server owns the money
    if onCooldown(player) then return end                  -- rate limit
    grant(player, item)
end)
```

- Assume every argument from a client is forged. Check its type, range and ownership, and rate
  limit. The server decides outcomes such as damage, currency and position checks. The client
  only asks.
- RemoteEvent for one-way messages. Avoid `RemoteFunction:InvokeClient` from the server: it
  waits on a client that may error, leave or never answer. For frequent, droppable updates
  (effects, cosmetic positions), use `UnreliableRemoteEvent`.
- Never `require(assetId)` or insert free-model scripts without reading them. A hidden
  `require(1234567)` is the classic backdoor.

## Player data

```lua
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local store = DataStoreService:GetDataStore("PlayerData_v1")
local sessions: { [Player]: any } = {}

local function load(player: Player)
    local ok, data = pcall(function()
        return store:GetAsync(tostring(player.UserId))
    end)
    if not ok then
        player:Kick("Couldn't load your data, please rejoin.") -- don't play on, or you overwrite their save
        return
    end
    sessions[player] = data or { coins = 0 }
end

local function save(player: Player)
    local data = sessions[player]
    if not data then return end                         -- never loaded: don't save over it
    local ok, err = pcall(function()
        store:UpdateAsync(tostring(player.UserId), function()
            return data
        end)
    end)
    if not ok then warn("save failed", player.UserId, err) end
end

Players.PlayerAdded:Connect(load)
for _, p in Players:GetPlayers() do task.spawn(load, p) end  -- players who joined first
Players.PlayerRemoving:Connect(function(p) save(p); sessions[p] = nil end)
game:BindToClose(function()
    for _, p in Players:GetPlayers() do task.spawn(save, p) end
    task.wait(2)
end)
```

Data store calls can fail and are rate limited, so always use `pcall`. Use `UpdateAsync` for
read-modify-write. Save on leave and in `BindToClose`, and check
`DataStoreService:GetRequestBudgetForRequestType` before bursts. Data stores work only on the
server, and in Studio only when API access is enabled in Game Settings.

## Typed Luau

Start files with `--!strict`. Annotate function parameters and returns. Export shared shapes
from modules (`export type Item = { id: string, price: number }`). Use `typeof(x)` (not `type`)
to check Roblox types (`typeof(v) == "Vector3"`). Fix type errors rather than switching a file to
`--!nonstrict`.

## Rojo project layout

```json
{
  "name": "MyGame",
  "tree": {
    "$className": "DataModel",
    "ReplicatedStorage": { "Shared": { "$path": "src/shared" } },
    "ServerScriptService": { "Server": { "$path": "src/server" } },
    "StarterPlayer": { "StarterPlayerScripts": { "Client": { "$path": "src/client" } } }
  }
}
```

`*.server.luau` becomes a Script, `*.client.luau` a LocalScript, other `.luau` files
ModuleScripts. `init.luau` / `init.server.luau` turns its folder into that script. Wally
packages usually go in `Packages/` under ReplicatedStorage.

## Patterns that avoid common bugs

- Characters respawn: use `player.CharacterAdded`, and
  `local character = player.Character or player.CharacterAdded:Wait()` on the client.
- `WaitForChild` for things that replicate in. Pass a timeout where missing is possible, then
  handle `nil`. `FindFirstChild` returns `nil`, so check it.
- Prefer events over polling loops. A `while true do` loop must yield every iteration
  (`task.wait()`), or the script times out. Server per-frame work goes on `RunService.Heartbeat`.
  `RenderStepped` / `BindToRenderStep` are client-only, for camera and visuals.

## Rules for agents

1. Decide where each piece of code runs before writing it, and say which file and container.
2. Never write the deprecated APIs above, even when the old code around it uses them. If the
   user didn't ask for a cleanup, mention the old ones instead of rewriting them.
3. Every new RemoteEvent handler validates its arguments on the server.
4. Data saving code always uses `pcall`, never saves after a failed load, and is tested in
   Studio with API access on.
5. With a Roblox Studio MCP connected: read scripts and the tree before editing, change only
   what was asked, and never publish the place or insert marketplace assets without asking.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.