Lesson 4 of 4
Security: never trust the client
Learn Roblox game security with Beacon Yard. Server validation, rate limits, movement sanity checks, Toolbox backdoors and require-by-id malware, the common exploit types, and why client anti-cheat is weak, with runnable checks.
By the end you can
- Build a small threat model: what must stay true, and which entry points a client can reach
- Validate a request on the server by shape, permission, distance and rate, using Beacon Yard's real checks
- Write a movement sanity check, and say why it is a heuristic
- Explain how a free model can hide a backdoor, how require-by-id malware works, and why client-side anti-cheat is weak
- Quarantine an untrusted model in a sandboxed container with the fewest script capabilities
Before this: Remotes: events, functions, unreliable, buffers, Types: strict mode, the new type solver, generics
1The note that says 9999 coins
Open the Studio command bar on the client during Play and run:
game.ReplicatedStorage.Remotes.ShopBuy:FireServer("Speed", 9999, "I am rich")
The shop never reads the 9999 or the claim. ShopService.purchase takes the player the engine supplied and the item, and nothing else. The price, the balance and the owner of the profile all come from the server's own tables.
function ShopService.purchase(player: Player, item: unknown)
if item == "Speed" then
buySpeed(player)
return
end
if item == "Shield" then
buyShield(player)
return
end
if item == "CoinPack" then
MonetizationService.prompt(player)
return
end
feedback(player, "deny", "Unknown item")
That is the whole idea of this lesson in three lines. The client can send anything. The server decides using only what the server already knows.
A client fires ShopBuy with the arguments ("Speed", 9999) and has 3 coins. What does ShopService.purchase use to decide?
Answer
The item name, the price from Config (25), and the coins in the server's profile (3). purchase(player, item) never receives the 9999. It looks up Config.SPEED_PRICE (25) and trySpend checks the real balance, 3, so the buy is denied with Not enough coins.
Open this step in lesson mode · Link to this step · This confused me
2A threat model in four columns
Security work starts with a list, before any code: what must stay true, and every door a client can reach it through. In Beacon Yard the things that must stay true are the profile's coins, the speed flag, the shield charge, the drone's health and the Coin Pack grant. The HUD number and the player's WalkSpeed are copies a client can write, so they are not assets.
The doors are the entry points: ShopBuy, Swing, a Touched event on a coin, and the purchase-receipt callback. ShopOpen is not a door that changes coins; the prompt only asks the server to show a menu.
| In the picture | In Roblox |
|---|---|
| A note arriving at the desk | A remote event reaching OnServerEvent |
| Checking the note against the real scoreboard | Comparing the request with Config and the server's profile |
| Refusing the note | Returning early or sending a deny Feedback |
The server is a clerk who checks every note against the real scoreboard before acting on it. A note that says "give me 9999 coins" is just paper.
Think of it as The clerk checks the scoreboard
Match each entry point to the server function that decides it.
Answer
ShopBuy remote: ShopService.purchase; Swing remote: CombatService.trySwing; A part touching a coin: The Touched handler in CoinService; A developer product purchase: The receipt handler in MonetizationService. Every route that can change an asset ends in one server function. A new remote without a row in this list has no reviewed check.
Open this step in lesson mode · Link to this step · This confused me
3Four checks: shape, permission, distance, rate
A good handler asks four questions, in order of cost:
- Shape. Is it the right kind of value, and a sane one? Beacon Yard's
trySwingwants twoVector3values, both finite, with a direction longer than a thousandth of a stud. - Permission. Is the sender allowed right now? The swing needs a Wrench equipped, not just owned.
- Distance. Is the claim physically possible? The origin must be within 8 studs of the head. A coin pays only if the player's root part is within 12 studs.
- Rate. Has the sender done this too often? Swings are 0.4 seconds apart at least.
Only after all four does the server apply its own number, WRENCH_DAMAGE of 34. The client never supplied it.
function CombatService.trySwing(player: Player, origin: unknown, direction: unknown): string
if typeof(origin) ~= "Vector3" or typeof(direction) ~= "Vector3" then
return "rejected"
end
if not isFiniteVector(origin) or not isFiniteVector(direction) then
return "rejected"
end
if direction.Magnitude < 1e-3 then
return "rejected"
end
local character = player.Character
if character == nil then
return "rejected"
end
local tool = character:FindFirstChild("Wrench")
if tool == nil or not tool:IsA("Tool") then
return "rejected"
end
local head = character:FindFirstChild("Head")
if head == nil or not head:IsA("BasePart") then
return "rejected"
end
if (origin - head.Position).Magnitude > ORIGIN_MAX_STUDS then
return "rejected"
end
local now = workspace:GetServerTimeNow()
local previousSwing = lastSwing[player]
if previousSwing ~= nil and now - previousSwing < SWING_GAP then
return "rejected"
end
lastSwing[player] = now

Select a numbered pin, or a row below, to read what it marks.
CombatService's two constants. Neither is in Config, so a client reading Config learns nothing about them.
Match each number to what it limits in Beacon Yard at m06.
Answer
8 studs: How far a swing's origin may be from the player's head; 12 studs: How far a player's root part may be from a coin when it pays; 14 studs: The length of the ray the server casts for a swing; 0.4 seconds: The minimum gap between two accepted swings. ORIGIN_MAX_STUDS is 8, the coin's reach is a literal 12, WRENCH_RANGE in Config is 14 and SWING_GAP is 0.4. Three different distances protect three different claims.
Open this step in lesson mode · Link to this step · This confused me
4Write the checks yourself
The cell below is a toy shop with the same four questions. Run it, then read the output against the code: every forged request is stopped by a different check.
local PRICES = { Speed = 25, Shield = 40 }
local profile = { coins = 30 }
local lastBuy = nil
local function purchase(item, now)
if lastBuy ~= nil and now - lastBuy < 0.5 then
return "no Too fast"
end
lastBuy = now
local price = PRICES[item] -- the table is the server's; item is only a key
if typeof(item) ~= "string" or price == nil then
return "no Unknown item"
end
if profile.coins < price then
return "no Not enough coins"
end
profile.coins -= price
return "ok " .. item .. " " .. profile.coins
end
print(purchase("Speed", 0)) -- 30 coins, price 25
print(purchase("Shield", 1)) -- 5 coins left, price 40
print(purchase("Free", 2)) -- not a real item
print(purchase({ "Speed" }, 3)) -- a table, not a string
print(purchase("Speed", 3.1)) -- 0.1 seconds after the last request
ok Speed 5
no Not enough coins
no Unknown item
no Unknown item
no Too fastIn the toy shop, lastBuy is written before the item is checked. Why not write it only after a successful purchase?
Answer
A burst of failing requests would never be slowed, because only successes would move the clock. Spam is mostly failing requests. If only successes updated the clock, a flood of bad ones would run unlimited. Recording the attempt, whatever happens next, limits the sender, not just the buyer.
Open this step in lesson mode · Link to this step · This confused me
5Movement: the part the client owns
Most checks work because the server owns the thing being changed. Movement is different: each client simulates its own character and sends the result up, otherwise walking would lag. A modified client can therefore report a position it never walked to, or set WalkSpeed to any value locally1.
Roblox's guidance is plain: there is no universal solution. A server check compares where a player was with where they are, over the time between. Three details matter:
- Allow for latency. Positions arrive late and in bursts, so average over time and add a tolerance, or honest players on bad connections get flagged.
- Measure on the ground plane. Project onto X and Z so jumping and falling do not count as running.
- Exempt legitimate teleports. A teleport pad or respawn is not cheating, so the game must tell the check.
Beacon Yard does not have a movement check at m06. Its speed numbers (16 normally, 24 with the upgrade) are what a check would be built from. The cell below is such a check, as a heuristic.
local WALK, BOOST, TOLERANCE = 16, 24, 1.5
local function flat(from, to)
return Vector3.new(to.X - from.X, 0, to.Z - from.Z).Magnitude
end
-- true when the move is believable for this player
local function moveOk(from, to, seconds, hasBoost, justRespawned)
if justRespawned then
return true
end
local speed = if hasBoost then BOOST else WALK
return flat(from, to) <= speed * seconds * TOLERANCE
end
local a = Vector3.new(0, 3, 0)
print("ok", moveOk(a, Vector3.new(18, 3, 0), 1, false, false)) -- 18 studs in 1 s, limit 24
print("fast", moveOk(a, Vector3.new(30, 3, 0), 1, false, false)) -- 30 studs, limit 24
print("teleport", moveOk(a, Vector3.new(200, 3, 0), 1, true, false)) -- 200 studs, limit 36
print("ok after respawn", moveOk(a, Vector3.new(200, 3, 0), 1, true, true))
ok true
fast false
teleport false
ok after respawn trueUsing the cell's check with TOLERANCE 1.5: a player with the Speed upgrade (BOOST_SPEED 24) is measured over 2 seconds. What is the farthest flat distance, in studs, that still passes?
Answer
72 studs. 24 * 2 * 1.5 = 72 studs. The tolerance is the room you give honest players with laggy connections. It is also the room a cheater has.
Open this step in lesson mode · Link to this step · This confused me
6What attackers actually do
Cheaters are not one kind of person with one trick. A few families cover most of what you will meet:
- Remote abuse. Fire a remote with forged, extreme or malformed arguments, or far too often. Defence: the four checks.
- Local tampering. Change values on their own client: WalkSpeed, a fake coin count, a GUI. Harmless if the server ignores the copy, harmful if it believes it.
- Movement and physics exploits. Teleport, fly, or take control of loose parts through network ownership. Defence: server movement checks, and anchoring or owning parts that matter.
- Reading the client. Anything replicated can be read, and scripts that reach the client can be decompiled. Server-only scripts in ServerStorage or ServerScriptService never replicate, so they cannot be2.
- Backdoors. Code hidden in something you installed yourself, which runs on your server with full power. The next step is about these.
Match each exploit to the defence that actually stops it.
Answer
Firing ShopBuy 500 times a second: A per-player rate limit on the server; Setting WalkSpeed to 100 on the client: A server movement check, not trusting the client's speed; Reading your server-only logic from the client: Keep it in ServerScriptService or ServerStorage; A hidden require in a free model: Reading scripts before you install them. Remote floods need a server-side limit. Client speed values are only believable after a server check. Server-only code stays private because it never replicates. A backdoor is stopped before it ever runs, by inspecting what you install.
Open this step in lesson mode · Link to this step · This confused me
7Toolbox backdoors and require-by-id
The Toolbox is full of free models, and many of them contain scripts. Most animate a door or play a sound. A few hide a backdoor: a short script that gives its author control of your game.
The classic trick uses require with a number. A ModuleScript uploaded to Roblox with the name MainModule can be loaded with require(assetId). That works on a server only and errors on a client, and other users can load it only when the model is public, which is why a backdoor author publishes theirs. The code then runs inside your game3. A backdoor is one line, often hidden under a boring name in a model's deep folders, that requires someone else's uploaded module. Whatever that module contains now runs with the power of your own server scripts, and its author can change it later without touching your game.
Defences, from cheapest to strongest:
- Look at the scripts in anything you install: search the model for
require(followed by a long number, and for scripts with strange names. - Install the model, then use Disable Scripts on it in Explorer, if you only need the parts4.
- Keep account ids and asset ids in one reviewed place, so an id anywhere else is a red flag. Beacon Yard does this and enforces it in CI.
const LONG_NUMBER = /(?<![\w.])\d{9,}(?!\w|\.\d)/g;
The id guard was built so real account ids do not leak, but it works against backdoors too: a nine-digit number that is not in Ids.luau fails the build.
The cell below scans lines of code for a numeric require. It is a toy version of what a reviewer, or a CI job, does.
local files = {
'local Config = require(script.Parent.Config)',
'local Remotes = require(script.Remotes)',
'task.spawn(function() require(123456789012).run() end)',
'local ok = pcall(function() return 1 end)',
'local m = require( 4455667788 )',
}
local found = 0
for index, line in files do
local call = string.match(line, "require%s*%(%s*%d+%s*%)")
if call then
found += 1
print(`line {index}: {call}`)
end
end
print(found, "suspicious")
line 3: require(123456789012)
line 5: require( 4455667788 )
2 suspiciousA free model contains a script with require(<a long number>). Why is that more dangerous than a script that only plays a sound?
Answer
The required module's code is controlled by its uploader and runs in your server with your scripts' power, and can change after you install it. The module lives on Roblox under its author's account. Your game loads whatever it contains at that moment, so you cannot read it by reading your own place, and it can change later.
Open this step in lesson mode · Link to this step · This confused me
8A quarantine folder for free models
Read every script before using a free model. Studio also blocks high-risk script capabilities on new Creator Store inserts. To configure your own sandboxed container or adjust its capabilities manually, enable the client-beta controls by setting Workspace.SandboxedInstanceMode to Experimental5.
Then a Model, Folder or Script has a Sandboxed property. Tick it, and scripts inside can do only what its Capabilities list allows. A few that matter for free models:
- RunServerScript: without it, a server script inside does not start at all, and Output shows a warning.
- CreateInstances: needed for
Instance.newandClone. - LoadUnownedAsset: needed for
requirewith an asset id, the backdoor line from the last step. - AccessOutsideWrite: without it, a script can only reach instances inside its own container. The docs advise never granting it.
A missing capability stops the call with an error that names it, such as The current thread cannot call 'Clone' (lacking capability CreateInstances). Try it on a stand-in for a free model, in a copy of the yard you will not publish. Never test with a real backdoored model.
Build along
Open a copy of the yard's place. Set
Workspace.SandboxedInstanceModetoExperimental, add a Folder namedQuarantineto Workspace, and tick itsSandboxedproperty.You should see Workspace shows SandboxedInstanceMode Experimental, and a Folder named Quarantine has Sandboxed ticked and an empty Capabilities list.
Inside
Quarantine, add a Model namedFreeCratewith a Script:print("free crate running"), thenlocal part = Instance.new("Part"),part.Parent = workspace, andrequire(1234). Press Play.You should see On Play, Output shows a warning that the script cannot start because it lacks RunServerScript, and nothing from the script runs.
Stop, add only
RunServerScriptto the folder'sCapabilities, and press Play again.You should see The print appears, then the Instance.new line stops with an error that names a missing capability, such as CreateInstances. No part appears and require never runs.
Delete the
Quarantinefolder and close the copy without publishing.You should see The place is back as it was, with no Quarantine folder.
A free windmill model only sets the AngularVelocity of a HingeConstraint motor inside its own model. Which capabilities do you grant its sandboxed container?
Answer
RunServerScript and Physics, and nothing that reaches outside the model. Least privilege: start with nothing, run it, and add only the capability each error names. A windmill that asks for network access or unowned assets is telling you something.
Open this step in lesson mode · Link to this step · This confused me
9Why client-side anti-cheat is weak
A common first idea is a script on the client that watches for cheating: it checks WalkSpeed and kicks the player if it is too high. It feels safe. It is not, for one reason: the cheater controls the machine that script runs on.
They can delete the script, stop it from running, change what it reads, or answer its questions with lies. Roblox's own security guide says client-side enforcement will eventually be bypassed, and that this is a basic fact of client-server design rather than a Roblox flaw6. A client check is only useful for friction and for reporting suspicious cases to the server. The decision has to be made where the cheater cannot reach.
Server sideRemember: Server validation is the clerk checks the scoreboard.
Where does it break?“The clerk checks the scoreboard” is a good picture of server validation. Where does it stop being true?
It breaks here. A clerk checks only what they remember to check, so every field of every note is a place a check can be missing; one unchecked note is the exploit. Some claims, such as a position the client simulated itself, cannot be checked against anything, only judged as plausible.
The true model. Validation is a function per entry point: shape, permission, distance, rate, then the server's own numbers. Anything the client can both send and have believed is a hole. Where the client owns the state, as with its own movement, the server can only apply heuristics.
Beacon Yard's server checks every Swing. A teammate suggests also adding a LocalScript that stops the swing button when it detects a macro. What is that script worth?
Answer
Friction at best; a cheater can remove it, so the server checks must stay the real defence. A LocalScript runs on the player's machine, where the player controls it. It can slow down casual abuse, but trySpend, SWING_GAP and the distance checks on the server are what hold.
Open this step in lesson mode · Link to this step · This confused me
10Build it: close the shop's open door
Beacon Yard's honest gap at m06 is that ShopBuy has no rate limit, while Swing does. Studios choose from a few approaches to this whole problem.
Ways to keep a game honest
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Server-side validation | Check every request against the server's own state. Beacon Yard's approach. | Always. It is the foundation under every other option. | You must write and test a check for every entry point, and movement checks are heuristics that need tuning. |
| Server authority model | Roblox's documented architecture (Workspace.AuthorityMode = Server) where the server simulates characters from client input while clients predict and roll back. | Competitive games where movement itself must not be faked. | Requires Deferred signals, Input Action System, StreamingEnabled and fixed simulation; physics and combat must be written for rollback. |
| Device Trust API | IntegrityService.EvaluatePlayerDeviceTrust and Player.DeviceTrustLevel rate how tamper-resistant a player's device is (Pending, Unknown, None, Standard, Full). | Gating sensitive features like trading or matching players of similar device trust, on top of server checks. | Optional and leaves all action to you; supported on Android, Chromebook and Meta Quest today (Web reports None; iOS, desktop and consoles currently report Unknown). |
| Telemetry and moderation | The server logs suspicious events (impossible speed, repeated denials) and a person or a rule reviews and acts. | Games with a competitive economy or a community that reports cheaters. | Slow, needs people, and false positives hurt honest players. |
| Client-side anti-cheat scripts | Local scripts that look for cheating and report or kick. | As friction on top of server checks, never alone. | The cheater controls the machine, so these can be removed, so they cannot be relied on. |
Two engine tools extend this foundation once a game grows. Roblox's Server Authority model moves simulation onto the server with client prediction and rollback7, covered hands-on in Server authority. The Device Trust API reports hardware and OS integrity on supported platforms without taking action itself8, which you combine with a shared remote wrapper and cross-server strike sync in Security at scale.
Build along
src/server/ShopService.luau
Check out
m06-drone-wrench, runrojo serve, press Play, and in the client command bar rungame.ReplicatedStorage.Remotes.ShopBuy:FireServer("Speed", 9999, "I am rich").You should see The HUD at the bottom of the screen shows the usual deny or buy toast, and your coin count is unchanged by the 9999.
Run the same call twice in one line:
local r = game.ReplicatedStorage.Remotes.ShopBuy r:FireServer("Speed") r:FireServer("Speed"). At m06, nothing slows the second call.You should see A Not enough coins or Already owned toast appears; no second purchase happens.
Open
src/server/CombatService.luauand find the two constants.You should see Studio shows CombatService with ORIGIN_MAX_STUDS equal to 8 and SWING_GAP equal to 0.4.
Open this step in lesson mode · Link to this step · This confused me
11Challenges
Level 1, Apprentice
Challenge
Fill in the threat model for Beacon Yard's four entry points.
- Start from
- The game at milestone m06 (download)
Done means
- A four-row table: swing, shop, coin, Coin Pack
- Each row names the asset, the entry point, the existing control and what the client must not decide
- Swing names the 8 stud cap and damage 34; the shop names prices 25 and 40; the coin names 12 studs and 5 coins
Hints
- The asset column is the profile, the drone's health or the receipt record. The HUD is not an asset.
- Use the numbers from Config and CombatService, and do not invent a remote.
-- moveOk(from, to, seconds, speed) is true when the flat (X and Z) distance
-- from -> to is at most speed * seconds * 1.5. Height must not count.
local function moveOk(from, to, seconds, speed)
return true
end
Level 3, Professional
Challenge
Rate-limit the shop on the server. The written solution, including the edit to the suite's shop_shield check, is challenges/solutions/security.md in the game repo.
- Start from
- The game at milestone m06 (download)
- Grade it
- To grade work from an earlier milestone, apply your challenge changes to a checkout based on
m14-ship, which includes the Course Runner. In Studio, press Play, then runrequire(game.ReplicatedStorage.GameTests.RunChallenge)("security")in the client command bar. Copy the pass code from Output.
Done means
- ShopService.purchase records workspace:GetServerTimeNow() per player before the item branches
- A second purchase right after the first is denied with the Feedback text Too fast (self-check, the test cannot see it: the gap is 0.5 seconds)
- Self-check, the test cannot see it: the shop_shield check in tests/init.luau waits out the new gap and still expects the shield to be bought
- The Course Runner prints TEST PASS security_shop_rate and a pass code
Hints
- Copy the shape of SWING_GAP in CombatService.
- Store the time even when the buy later fails for coins, so a burst of failures is limited too.
- The deny text has to be exactly Too fast. The test looks for that string on Feedback.
- FireServer runs on the client and hits the live server module; a require of ShopService from the server command bar is a different copy with an empty table.
Open this step in lesson mode · Link to this step · This confused me
12Recap
Retiring the analogy
You no longer need “the clerk checks the scoreboard”. Validation is a function per entry point: shape, permission, distance, rate, then the server's own numbers. Anything the client can both send and have believed is a hole. Where the client owns the state, as with its own movement, the server can only apply heuristics.
Recap
- A threat model lists what must stay true and every entry point that can change it. Each handler checks shape, permission, distance and rate, then applies its own numbers, never one the client sent.
- The client owns its character, so movement checks on the server are heuristics: allow for latency, measure on the ground plane, and exempt real teleports. WalkSpeed on a client is only a copy.
- Free models can hide backdoors such as require-by-id, which run with your server's power. Inspect what you install, keep ids in one guarded place, and remember a client-side anti-cheat can always be removed.
- Studio blocks high-risk capabilities on new Creator Store inserts. The client-beta controls let you set capabilities on your own sandboxed container. Start with none and add only what your scripts need.
Server validation is the clerk checks the scoreboard, until a clerk checks only what they remember to check, so every field of every note is a place a check can be missing; one unchecked note is the exploit. Some claims, such as a position the client simulated itself, cannot be checked against anything, only judged as plausible.
A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.
Queued for review
- A client fires ShopBuy with the arguments ("Speed", 9999) and has 3 coins. What does ShopService.purchase use to decide?
- Match each entry point to the server function that decides it.
- Match each number to what it limits in Beacon Yard at m06.
- In the toy shop, lastBuy is written before the item is checked. Why not write it only after a successful purchase?
- Using the cell's check with TOLERANCE 1.5: a player with the Speed upgrade (BOOST_SPEED 24) is measured over 2 seconds. What is the farthest flat distance, in studs, that still passes?
Open this step in lesson mode · Link to this step · This confused me