rate my own server authority gng:
Folder setup
ServerScriptService
├─ ServerAuthority.server.lua
└─ Authority
├─ Validator.lua
├─ RateLimiter.lua
└─ PlayerState.lua
ReplicatedStorage
└─ Remotes
└─ ActionEvent (RemoteEvent)
RateLimiter.lua
Basic per-player throttling. Cheap, effective, boring (which is good).
local RateLimiter = {}
RateLimiter.__index = RateLimiter
function RateLimiter.new(limit, window)
return setmetatable({
limit = limit,
window = window,
calls = {}
}, RateLimiter)
end
function RateLimiter:Allow(player)
local now = os.clock()
local record = self.calls[player] or {count = 0, reset = now + self.window}
if now > record.reset then
record.count = 0
record.reset = now + self.window
end
record.count += 1
self.calls[player] = record
return record.count <= self.limit
end
function RateLimiter:Cleanup(player)
self.calls[player] = nil
end
return RateLimiter
PlayerState.lua
Server-owned truth. Clients never write to this.
local PlayerState = {}
local states = {}
function PlayerState.Init(player)
states[player] = {
Health = 100,
Position = Vector3.zero,
LastValidCFrame = nil,
}
end
function PlayerState.Get(player)
return states[player]
end
function PlayerState.Remove(player)
states[player] = nil
end
return PlayerState
Validator.lua
This is where exploits go to die.
local Validator = {}
local MAX_DISTANCE = 20 -- studs per update
function Validator.ValidPlayer(player)
return player and player:IsA("Player") and player.Character
end
function Validator.ValidMovement(player, newCFrame, state)
if not state.LastValidCFrame then
state.LastValidCFrame = newCFrame
return true
end
local delta = (newCFrame.Position - state.LastValidCFrame.Position).Magnitude
if delta > MAX_DISTANCE then
return false
end
state.LastValidCFrame = newCFrame
return true
end
function Validator.ValidAction(action)
return typeof(action) == "string"
end
return Validator
ServerAuthority.server.lua
This is the actual authority. The server decides everything.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ActionEvent = ReplicatedStorage.Remotes.ActionEvent
local RateLimiter = require(script.Authority.RateLimiter)
local Validator = require(script.Authority.Validator)
local PlayerState = require(script.Authority.PlayerState)
local actionLimiter = RateLimiter.new(10, 1) -- 10 actions per second
Players.PlayerAdded:Connect(function(player)
PlayerState.Init(player)
end)
Players.PlayerRemoving:Connect(function(player)
PlayerState.Remove(player)
actionLimiter:Cleanup(player)
end)
ActionEvent.OnServerEvent:Connect(function(player, payload)
if not Validator.ValidPlayer(player) then return end
if not actionLimiter:Allow(player) then
warn("Rate limit hit:", player)
return
end
local state = PlayerState.Get(player)
if not state then return end
-- Example payload:
-- {action = "Move", cframe = CFrame}
if not Validator.ValidAction(payload.action) then return end
if payload.action == "Move" then
if typeof(payload.cframe) ~= "CFrame" then return end
if not Validator.ValidMovement(player, payload.cframe, state) then
warn("Invalid movement:", player)
return
end
player.Character:PivotTo(payload.cframe)
end
-- Extend here:
-- Combat
-- Abilities
-- Inventory
end)
Client rule (important)
Clients request, servers decide.
Bad client:
character:PivotTo(cframe)
Correct client:
ActionEvent:FireServer({
action = "Move",
cframe = cframe
})