Performance is measured on the player's machine — learn the frame budget, the per-frame work that eats it, and how to measure before you optimize.
Your server code might be perfect, but if the 's own machine drops frames, your game feels broken to them. Client performance lives and dies by one number: how long each frame spends doing your work.
There are two kinds of lag, and they have different causes:
You only see server lag from the server side. You feel client lag on your own screen — but so does every on their own hardware, no matter how fast your server is.
A game that plays well must stay under its per-frame budget on the weakest 's machine you care about, not on your gaming PC.
Your game runs at 120 FPS on your computer but drops to 30 on a phone. Where is the problem?
One frame — one picture on screen — happens 60 times a second at 60 FPS. That gives each frame about 16 milliseconds to fit in everything: physics, , and rendering.
Two timers drive per-frame work:
Work in either timer is work every single frame. Ten lines of code in a timer is ten lines × 60 frames = 600 lines of work a second, forever, as long as it runs. That's fine when the work is cheap — it's a disaster when each frame does searching, building, or timing that doesn't need to happen.
The frame budget doesn't care why the frame is slow. Cross 16 ms and frames drop.
At 60 FPS, each frame has about milliseconds to do all its work.
A per-frame is a promise: "I have something important to do every frame." Most per-frame break that promise immediately.
-- RenderStepped: runs before the render, every single frame
local function onRender(dt)
local icon = workspace.UI.Icon -- searching every frame
local label = workspace.UI.MoneyLabel -- searching every frame
MoneyLabel.Text = "Coins: " .. counts -- rebuilding + re-laying out UI every frame
end
RunService.RenderStepped:Connect(onRender)
-- Heartbeat: runs after physics, every frame
local function onHeartbeat(dt)
updateEverything() -- is this really needed every frame?
end
RunService.Heartbeat:Connect(onHeartbeat)
The rule for both timers: do in the timer only what must happen this frame. Cache anything that doesn't change, and skip the work entirely on frames where the result would be identical.
RenderStepped fires before the render — which of these is a legitimate use?
Most client lag comes from the same four habits, one per section below.
1. Unnecessary and repeated searches. Searching the data model inside a per-frame re-walks the entire hierarchy every frame:
-- ❌ searches the whole workspace 60 times a second
RunService.RenderStepped:Connect(function()
local coin = workspace:FindFirstChild("Coin")
if coin then coin.CFrame = coin.CFrame * offset end
end)
-- ✅ one search, one reference, reused forever
local coin = workspace:FindFirstChild("Coin")
RunService.RenderStepped:Connect(function()
if coin then coin.CFrame = coin.CFrame * offset end
end)
Caching a reference — grabbing it once when the starts — is the single highest-value client optimization beginners can learn.
2. Allocation churn. Building strings, , or every frame makes the garbage collector run constantly. Reusing a string or a instead of rebuilding it is free performance.
3. Expensive UI updates. Setting .Text every frame forces a layout + redraw of the label, even when the text is identical. Update a label only when its value actually changed.
4. Frame-budget overload. Add cheap work and nothing breaks. Add it to a timer that's already near 16 ms, and every small addition drops a frame. This is why measuring first matters.
The four costs aren't enemies to avoid at all costs — they're a checklist. When the game feels slow, open this list and hunt the timer first, the search second, the allocation third, and the UI write fourth.
Never rewrite code on vibes. Roblox ships the tools to see the frame budget with your own eyes:
debug.profilebegin("name") / debug.profileend() mark a section of your own code in the profiler, so you can time exactly one .The golden rule of the frame budget: a real bottleneck shows up in the numbers before you touch any code. If the profile says time is 2 ms out of 16, squabbling over micro-optimizations in a that runs three times a frame is polishing a donut while the render side is maxed out.
Your frame-time graph shows render time at 14 ms and script time at 1 ms. Where should you look first?
Here's the classic slow-client pattern, then the measured fix. The label is updated every frame even when nothing changed — and the icon is searched-for every frame:
-- ❌ before: searches + rebuilds + re-lays-out, 60 frames a second
local icon = nil
RunService.RenderStepped:Connect(function()
if not icon then icon = workspace.UI.Icon end -- search on frame 1 only
MoneyLabel.Text = "Coins: " .. game.ReplicatedStorage.Coins.Value -- rebuild every frame
end)
Even this "improved" version rebuilds the label string every frame. The measured fix watches the value and only repaints when it actually changed:
-- ✅ after: reads the displayed value, updates only when it changes
local coins = game.ReplicatedStorage.Coins.Value
local lastText = nil
RunService.RenderStepped:Connect(function()
local text = "Coins: " .. coinCount
if text ~= lastText then
MoneyLabel.Text = text
lastText = text
end
end)
The output is identical to the . The cost per frame is: no search, no string build unless the value changed, no UI layout unless the text changed.
Notice the difference between a bottleneck and a micro-optimization: the fix above removed per-frame searching, per-frame allocation, and per-frame UI work — the three things the profiler would show eating time. Changing local text = "Coins: " to "Coins:" .. would have been a micro-optimization — nothing measurable.
Here's a per-frame riddled with the exact costs from this lesson. Read it, spot the waste, then fix it: the pretends to be a frame timer, and inside it the number is read, a string is rebuilt every "frame", and the (imaginary) label would redraw every frame.
Make the loop rebuild the label string only when the coins value actually changes — not on every one of the 60 frames. Keep the same final label value, and keep every frame reading the current coins value (it can change while the loop runs). The hidden checks count how many times buildLabel is called.
Hint: Watch the value before building. If the value you're about to show is the same as the last one you built, the frame needs no label work at all.
Client performance is a budget, not a mystery:
Next: the flip side of performance — why things you thought were gone can stick around, and the three habits that keep dead code dead.