Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.
Validate identity, permission and distance
v2 · Activity 1 of 0 · input-validation · permission · distance · 28 min Requires Roblox Studio
Chapter outline
Type validation is only the first layer. The server maps an allowlisted ID to its own object instead of accepting a client table pretending to be an Instance.
Context validation checks server-owned permission, live character and distance. Never accept a client-supplied isAllowed or position as proof.
Your task
Create UseLamp and a server-owned WorkshopLamp. Initialize CanUseWorkshop=true for this practice lab. Accept only main-lamp, a live nearby character within 10 studs, and the server permission; rate-limit to once per second.
Interface: Complete the documented Studio hierarchy and self-check the behavior outside the browser.
| Input | Expected |
|---|
Syntax in this activity
New syntax: input-validation, permission, distance
Earlier ideas used here
- server-state
- authority
Self-check rubric
- Each validation layer has a rejection test.
- Set CanUseWorkshop=false from the server and confirm denial.
- A client payload table or client-only permission change is not accepted as authority.
Your explanation is a self-check. Exact wording is not automatically graded.
Self-checked Studio exercise. A saved checklist records your own review; no uploaded place file or screenshot is executed here.
Build this hierarchy
Workspace/WorkshopLamp (Part, Anchored=true) ReplicatedStorage/UseLamp (RemoteEvent) ServerScriptService/ValidateLamp (Script, RunContext=Server) StarterPlayer/StarterPlayerScripts/RequestLamp (LocalScript)
- Build WorkshopLamp near the spawn.
- Create UseLamp and the server script.
- For the local test, RequestLamp waits two seconds and calls UseLamp:FireServer("main-lamp"); walk near or far before the request.
ServerScriptService/ValidateLamp.server.luau
Main guided reference implementation; use the hierarchy’s stated Script or ModuleScript type.
local Players = game:GetService("Players")
local lamp = game:GetService("Workspace"):WaitForChild("WorkshopLamp")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("UseLamp")
local nextAllowed = {}
local function initialize(player) player:SetAttribute("CanUseWorkshop", true) end
Players.PlayerAdded:Connect(initialize)
for _, player in ipairs(Players:GetPlayers()) do initialize(player) end
Players.PlayerRemoving:Connect(function(player) nextAllowed[player.UserId] = nil end)
remote.OnServerEvent:Connect(function(player, objectId)
local now = os.clock()
if now < (nextAllowed[player.UserId] or 0) then return end
nextAllowed[player.UserId] = now + 1
if type(objectId) ~= "string" or objectId ~= "main-lamp" then return end
if player:GetAttribute("CanUseWorkshop") ~= true then return end
local character = player.Character
local root = character and character:FindFirstChild("HumanoidRootPart")
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if not root or not root:IsA("BasePart") or not humanoid or humanoid.Health <= 0 then return end
if (root.Position - lamp.Position).Magnitude > 10 then return end
lamp.Color = Color3.fromRGB(234,120,40)
print("Validated lamp request", player.UserId)
end)StarterPlayer/StarterPlayerScripts/RequestLamp.client.luau
Controlled client request; server still validates all meaningful context.
local remote = game:GetService("ReplicatedStorage"):WaitForChild("UseLamp")
local player = game:GetService("Players").LocalPlayer
if not player.Character then player.CharacterAdded:Wait() end
task.wait(2)
remote:FireServer("main-lamp")Expected output
- A permitted live nearby request colors the lamp and logs a validated request.
- Wrong ID, missing permission, dead/missing character and distant requests do not change it.
Studio assessment checklist
Multiplayer tests
- Two clients test different distances and server permission values.
- Send controlled wrong-type/unknown-ID payloads in the isolated place.
Troubleshooting and production considerations
Reset lamp color between rejection tests so an earlier valid action does not hide a failure.
Character spawning races should reject safely; do not assume the root always exists.
This is a bounded learning lab. It has not been executed in an approved Roblox Studio environment by this website.
A checked checklist records your own review, not automated project competence or a community verification.
Create UseLamp and a server-owned WorkshopLamp. Initialize CanUseWorkshop=true for this practice lab. Accept only main-lamp, a live nearby character within 10 studs, and the server permission; rate-limit to once per second.
Reset starter
Replace this code with the starter? Download your draft to keep a copy.
Code
Studio source fileEdit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.