RemoteEvent / RemoteFunction gotchas that fail silently

The Server-Client Communication page in the docs has a bunch of notes near the bottom that are easy to skip past if you only read the examples. These are the ones I think are worth knowing before you ship anything multiplayer.

The server doesn’t validate anything for you

Whatever the client passes to FireServer / InvokeServer shows up in your callback as-is. The only argument you can trust is the first one, player, because the server fills that in from the request itself. Everything after it could be anything.

Two things that get past a naive check:

  • NaN passes range checks, because every comparison against NaN is false. amount < 1 or amount > 99 is false for NaN, so it slips through.
  • Forged tables. A client can send a table that looks like an Instance. Check with typeof(x) == "Instance" before calling :IsA() on it.

The order the docs suggest is permission, then type, then range:

local function OnBuyItem(player, item, amount)
    -- 1. Permission (distance, state, cooldown, ownership...)
    if not CanPurchase(player) then
        return false
    end

    -- 2. Type
    if typeof(item) ~= "Instance" or not item:IsA("Tool") then
        return false
    end
    if typeof(amount) ~= "number" then
        return false
    end

    -- 3. Range
    if amount ~= amount then -- NaN is the only value not equal to itself
        return false
    end
    if math.abs(amount) == math.huge then -- Inf
        return false
    end
    if amount < 1 or amount > 99 then
        return false
    end

    return Purchase(player, item, amount)
end

C2S_BuyItem.OnServerInvoke = OnBuyItem

And never take a value from the client that the server already knows, like price or ownership.

A RemoteFunction with no callback hangs forever

If the client calls InvokeServer before the server has assigned OnServerInvoke, the calling thread just stops. No error, no timeout, no way to cancel it. So if “nothing happens at all” when you press a button, check your init order before anything else.

Related: OnServerInvoke is a property, not an event. No :Connect(), only one function is kept, and if you forget to return the client gets nil.

Errors in OnServerInvoke propagate to the client

If your server callback errors, the error is delivered to the calling client and interrupts the client code. Either return a success flag instead of erroring, or wrap the client call in pcall. RemoteEvent doesn’t have this problem, so if you don’t actually need a return value, use a RemoteEvent.

Don’t use InvokeClient

Server waiting on a client is a bad deal: if the client errors, it propagates to the server; if the client leaves mid-call, it errors; and if the client never returns, the server waits forever. A malicious client can do that last one on purpose. The alternative is FireClient plus a separate RemoteEvent for the reply.

Mixed tables lose data silently

Values get converted when they cross the boundary, with no warning:

  • Functions don’t make it. As a table value, the key is removed entirely.
  • If a table has both array items and named fields, the named fields disappear and numeric keys turn into strings.
  • Tables arrive as copies, so filling an argument table on the receiving side does nothing for the sender.
-- owner and callback both disappear here
C2S_Something:InvokeServer({ "Sword", "Bow", owner = "Diva", callback = OnDone })

-- nest the array, use a string id instead of a function
C2S_Something:InvokeServer({ items = { "Sword", "Bow" }, owner = "Diva", callbackId = "OnDone" })

This one is nasty because nothing errors. The data is just quietly not there.

Small habit that helps

The docs suggest prefixing remotes with C2S_ / S2C_. Sounds minor, but it makes it obvious at a glance which side is supposed to validate.

Source: Server-Client Communication

Has anyone settled on a nice pattern for per-player rate limiting on remotes? I’ve seen a few approaches and I’m curious what’s held up in practice.