Module 10 · Client and server
Validating every server request
Check type, range, ownership, distance, state, and permission before changing game state.
What you will learn
- Name six server validation categories
- Reject malformed and impossible requests early
- validation
- Runtime checks that data and game state meet a trusted rule.
- permission
- Whether an actor is allowed to perform an action.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A client can be modified, delayed, or mistaken. Coin Quest must make its own decision from server-observed state.
The mental model
Validate shape first, then locate server-owned objects, then check state such as ownership, distance, cooldown, and permission.
Reject with minimal public detail and keep the authoritative update after every guard.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
== is read as “equals equals”: it compares two values and produces a boolean.
~= is read as “not equal”: it asks whether two values differ.
if is read as “if”: it starts a decision by evaluating a condition.
then is read as “then”: it marks the body that can run when the condition is truthy.
end is read as “end”: it closes a block such as a decision, loop, or function.
A tiny example
--!strictlocal function canOpenDoor(player: Player, doorId: unknown): boolean if typeof(doorId) ~= "string" or #doorId > 40 then return false end local character = player.Character local door = workspace.Doors:FindFirstChild(doorId) if character == nil or door == nil or not door:IsA("BasePart") then return false end return (character:GetPivot().Position - door.Position).Magnitude <= 12endprint(canOpenDoor)Line by line
- 3
The function receives trusted Player identity and unknown client data.
- 4
Type and length are checked before lookup.
- 8
Character state comes from the server.
- 9
The server resolves the ID inside an allowed folder.
- 10
Missing and wrong-class objects are rejected.
- 14
Distance is calculated from server-visible objects.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Start with the statements outside function bodies. A function definition creates a callable value; its body runs when a call, event, or scheduled task reaches it.
Trace the arguments at each call and the branch or loop inside that call. Return to the caller when the function returns. For an event, use the action named in Try it to trigger the callback.
Line 3: The function receives trusted Player identity and unknown client data.
Line 4: Type and length are checked before lookup.
Line 8: Character state comes from the server.
Line 9: The server resolves the ID inside an allowed folder.
Line 10: Missing and wrong-class objects are rejected.
Line 14: Distance is calculated from server-visible objects.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: Every invalid category returns before any authoritative mutation.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
What happens for a 100-character door ID?
Try it
Mark each step after you have tried it.
Common mistake
Checking only that a client named a real Part is insufficient. The Part must be in an allowed set, near the player's server character, and in a valid state.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Treat client payload as unknown.
- Resolve allowed objects on the server.
- Validate state and permission before mutation.
Next: Next, you will limit how often even valid requests are processed.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.