RemoteEvent Payload Validator

A strict server-side Luau example that accepts only documented upgrade identifiers, integer levels, and known table fields.

Roblox Studio ModuleScript

What this script does

Demonstrate allow-list validation before a RemoteEvent request reaches currency, inventory, or upgrade logic.

Best for
Learning how to distrust client payloads in an experience you own.
Language
Luau
Version
1.0.0
Validation
Luau runtime tested
Luau runtime tested

Official Luau 0.735 parsing and strict analysis pass, and the module is covered by the pure-module runtime behavior harness.

Included behavior

  • Rejects unknown fields
  • Allow-lists action identifiers
  • Bounds integer quantities

Install in the stated runtime

  1. 1
    Create a ModuleScript named PayloadValidator.
  2. 2
    Paste the complete source and require it from a server or test Script in your own experience.
  3. 3
    Adapt the small schema to your own action, then validate rate, ownership, price, and state separately on the server.

Minimal usage example

local Validator = require(script.Parent.PayloadValidator)
local ok, request = Validator.upgradeRequest(payload)
if not ok or not request then return end
print(request.upgradeId, request.levels)

Example inputs and result

Supply
The untrusted upgrade-request payload received by your own server.
Expect
upgradeRequest returns validity and a checked request for further server-side authorization.

These notes explain the example above. Read the complete source for every exported function and edge case before integrating it.

Complete source

No hidden import, minified block, or shortened loader.

--!strict
-- MIT License. Server-side schema validation for a small RemoteEvent payload.

export type UpgradeRequest = { upgradeId: string, levels: number }
local PayloadValidator = {}
local allowedUpgrades = { base = true, treadmill = true, capacity = true }

function PayloadValidator.upgradeRequest(value: unknown): (boolean, UpgradeRequest?)
	if type(value) ~= "table" then return false, nil end
	local source = value :: { [any]: any }
	for key in source do
		if key ~= "upgradeId" and key ~= "levels" then return false, nil end
	end
	if type(source.upgradeId) ~= "string" or not allowedUpgrades[source.upgradeId] then return false, nil end
	if type(source.levels) ~= "number" or source.levels % 1 ~= 0 or source.levels < 1 or source.levels > 10 then return false, nil end
	return true, { upgradeId = source.upgradeId, levels = source.levels }
end

return table.freeze(PayloadValidator)
SHA-256f3ff0a711f540059b15a78fdb4b38337e362d2d7cfcc68ec745b1f14f5683b9e

Outside this script’s scope

  • Authorize a purchase by itself
  • Replace server-side ownership and balance checks

Found a problem or a better approach?

Tell us what failed, what you expected, and whether the issue happened in the Luau CLI or Roblox Studio. Suggestions for clearer types, safer server checks, or a more useful API are welcome.

Do not submit credentials, private project files, or account data.