Roblox Networking

作者 gamedev-skillsd4b0e35550c5無授權條款1.3K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫11 天前更新

Design and harden Roblox client/server networking with RemoteEvent, RemoteFunction, and UnreliableRemoteEvent; server authority, argument and Instance validation, rate limits, proximity/ownership checks, targeted replication, streaming, lifecycle, prediction, and reconciliation. Use for Roblox remotes, exploits, request spam, multiplayer replication, network ownership, high-frequency cosmetic updates, or server/client desynchronization.

AI 產生的概覽

指導 Roblox 用戶端/伺服器網路設計:遠端物件選擇、伺服器權威、驗證、限流、複製與預測。

功能
此技能提供使用 RemoteEvent、RemoteFunction 與 UnreliableRemoteEvent 設計並強化 Roblox 用戶端/伺服器通訊的說明。內容涵蓋訊息分類、精簡酬載、分層驗證、在伺服器端套用狀態變更、窄範圍複製、生命週期處理,以及帶對帳的預測。它包含經過驗證的遊戲請求與權杖桶限流的 Luau 範例,並提供故障/補救對照表和傳輸方式選擇指引。
適用情境
適用於設計、實作、偵錯或強化跨邊界的 Roblox 通訊,例如遠端物件信任用戶端數值、利用者針對任意 Instance、請求大量灌送、串流物件缺失,或用戶端與伺服器不同步。不適用於基礎 Luau/服務、持久化狀態或物理擁有權機制,這些由相關技能涵蓋。
執行需求
僅為說明文件,不附帶指令碼。它引用 Roblox 平台 API、一個隨附參考檔案(references/validation-and-testing.md)以及 agents/openai.yaml。驗證指引假定使用 Roblox Studio 的 Server & Clients 測試;未指定認證資料或外部套件。

Roblox networking

Build explicit request and replication contracts in which the server decides authoritative game state and clients provide input or intent. Targets Roblox's rolling platform APIs. This skill goes deeper than the networking primer in roblox-luau.

When to use

  • Use to design, implement, debug, or secure cross-boundary Roblox communication.
  • Use when a remote trusts client values, an exploiter can target arbitrary Instances, messages spam services, streamed objects are missing, or clients disagree with the server.

When not to use: basic Luau/services belong to roblox-luau; persistent state belongs to roblox-datastores; physical ownership mechanics also compose with roblox-physics.

Workflow

  1. Inspect the existing protocol. Find every remote and both endpoints; document direction, sender, payload, frequency, authority, validation, and consumers. Reuse the canonical remote folder—do not create a duplicate because discovery was skipped.
  2. Classify each message. Client request, server fact, or ephemeral cosmetic sample. Choose reliable event, unreliable event, or request/response from semantics—not convenience.
  3. Minimize the payload. Send stable identifiers and intent. Do not send a price, damage, ownership result, arbitrary path, or computed outcome the server can derive.
  4. Validate in layers. Check type/shape/finiteness, allowlisted value, Instance class and ancestry, player permissions/state, distance/line of sight where relevant, server cooldown, and rate budget before doing expensive work.
  5. Apply on the server. The server resolves targets and mutates health, inventory, currency, cooldowns, and progression. Client-side checks improve UX but grant no trust.
  6. Replicate narrowly. Use FireClient for private or local facts; broadcast only shared facts. Avoid sending replicated properties again unless the client needs a distinct presentation event.
  7. Handle time and lifecycle. Requests may arrive after death, respawn, streaming changes, or disconnect. Resolve the current character/state during handling and clean per-player limiter data.
  8. Verify with Server & Clients. Exercise normal, malformed, spam, out-of-range, stale character, rapid respawn, leaving, simultaneous players, targeted, and broadcast cases. Inspect server and each client Output separately.

Choose the transport

PrimitiveUseDo not use
RemoteEventordered, reliable one-way requests/factscontinuous samples where newer replaces older
UnreliableRemoteEventephemeral cosmetic/continuous state tolerant of loss and reorderingpurchases, damage decisions, inventory, one-shot state transitions
RemoteFunctionbounded client-to-server query that truly needs an immediate replyserver-to-client invocation; long/uncertain work; ordinary commands

Never invoke a client synchronously from the server. A client may disconnect, error, or never return. Prefer server RemoteEvent:FireClient() and a separate response event when needed.

Pattern: validate before resolving gameplay

lua
-- ServerScriptService/CombatRequests.server.luaulocal Players = game:GetService("Players")local ReplicatedStorage = game:GetService("ReplicatedStorage")local Workspace = game:GetService("Workspace")
local attack = ReplicatedStorage.Remotes.Attacklocal lastRequest: {[Player]: number} = {}local RANGE = 12local COOLDOWN = 0.25
attack.OnServerEvent:Connect(function(player: Player, target: unknown)    local now = Workspace:GetServerTimeNow()    if now - (lastRequest[player] or -math.huge) < COOLDOWN then return end    lastRequest[player] = now
    if typeof(target) ~= "Instance" or not target:IsA("Model") then return end    if not target:IsDescendantOf(Workspace.Characters) then return end    local targetHumanoid = target:FindFirstChildOfClass("Humanoid")    local targetRoot = target:FindFirstChild("HumanoidRootPart")    local character = player.Character    local root = character and character:FindFirstChild("HumanoidRootPart")    local humanoid = character and character:FindFirstChildOfClass("Humanoid")    if not targetHumanoid or not targetRoot or not root or not humanoid then return end    if humanoid.Health <= 0 or targetHumanoid.Health <= 0 then return end    if (root.Position - targetRoot.Position).Magnitude > RANGE then return end    if not serverCombatStateAllowsAttack(player, now) then return end
    targetHumanoid:TakeDamage(serverDamageFor(player))end)
Players.PlayerRemoving:Connect(function(player)    lastRequest[player] = nilend)

This is still only a compact example: a real melee system may require server-known attack windows, line-of-sight/shape checks, team rules, and lag policy. Do not treat one distance check as security.

Pattern: token bucket at the boundary

lua
type Bucket = {tokens: number, updatedAt: number}local buckets: {[Player]: Bucket} = {}local CAPACITY, REFILL_PER_SECOND = 6, 3
local function consume(player: Player, cost: number): boolean    local now = os.clock()    local bucket = buckets[player] or {tokens = CAPACITY, updatedAt = now}    bucket.tokens = math.min(CAPACITY,        bucket.tokens + (now - bucket.updatedAt) * REFILL_PER_SECOND)    bucket.updatedAt = now    if bucket.tokens < cost then buckets[player] = bucket; return false end    bucket.tokens -= cost    buckets[player] = bucket    return trueend

Assign cost by server impact. Reject cheaply before datastore calls, cloning, raycasts, or broad replication. Log aggregate abuse signals, not one warning per rejected packet.

Replication, streaming, and prediction

  • Replicated Instances/properties are already a state channel. Use remotes for intent, private state, or presentation cues, not an unconditional parallel copy of the DataModel.
  • With instance streaming, a valid server Instance may not exist on a client. Send a stable ID and tolerate absence; do not wait forever for optional streamed content.
  • High-rate cosmetic data may use UnreliableRemoteEvent; make each sample self-contained because delivery and order are not guaranteed. Payloads over 1000 bytes are dropped (Studio Output reports the overage). RemoteEvent and UnreliableRemoteEvent also share a throttle of roughly 500 calls/second per client, counted across all remotes of that type — which is what a legitimate player hits before any attacker does.
  • Predict only latency-sensitive reversible presentation. Include a client sequence/command ID; the server returns authoritative state and acknowledgement; the client corrects smoothly. Never let prediction award damage, currency, inventory, or progression.
  • Network ownership improves responsiveness but lets that client influence physical simulation. Validate gameplay consequences on the server; ownership is not authorization.

Common failures

SymptomLikely causeRemedy
exploiter chooses damage/priceoutcome accepted from clientsend intent/ID; derive and apply on server
arbitrary object can be deletedonly typeof(Instance) checkedvalidate class, ancestry, ownership, state, and allowlisted operation
server stalls on a playerserver invokes client RemoteFunctionreplace with asynchronous events
valid player triggers throttlingper-frame reliable messageslower frequency, state replication, batching, or unreliable cosmetics
old packet reverses new effectunordered unreliable samples treated as commandsmake samples replaceable/versioned; use reliable event for transitions
remote breaks after respawncached character/rootresolve current character during handling and reject stale state
private data leaksFireAllClients used by defaultuse FireClient and minimal payloads
distance check is bypassedclient-owned object moved near targetanchor/server-own critical object and validate full server context

Resources

  • Read references/validation-and-testing.md for payload rules, Instance/finiteness checks, replication design, and the required multi-client abuse matrix.

Related skills

  • roblox-luau — execution locations and basic RemoteEvent mechanics.
  • roblox-characters — respawn-safe character resolution.
  • roblox-physics — network ownership, ray/overlap validation, and physical consequences.
  • roblox-studio-workflow — Server & Clients testing and Output inspection.

Primary references

  • https://create.roblox.com/docs/scripting/events/remote
  • https://create.roblox.com/docs/scripting/security/client-server-boundary
  • https://create.roblox.com/docs/physics/network-ownership
  • https://create.roblox.com/docs/studio/testing-modes

來源與署名

來源:gamedev-skills/awesome-gamedev-agent-skills位於skills/other-engines/roblox-networking提交d4b0e35

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架