Strategic print statements turn a black box into a story — and reveal exactly which step failed.
Every senior developer's secret is embarrassing: they add print statements. Strategic prints turn a black box into a narrated story — and they're the fastest way to find where logic goes wrong.
Three prints tell you which step failed:
print("click received from", player.Name) -- did the event fire?
print("coins before:", coins.Value) -- what state did we enter?
coins.Value = coins.Value + 10
print("coins after:", coins.Value) -- did it change?
Your print('before') shows up, but print('after') never does. The bug is the two prints.
When you don't know where the problem is, don't guess — divide the code in half and print at the middle:
print("A: start")
-- ...setup...
print("B: got the part") -- half the distance
-- ...handler...
print("C: handler ran")
If "B" shows but "C" doesn't, the bug is between B and C. Narrow again inside that stretch. Each run halves the search — a few runs finds any bug.
Your print('before') shows up in Output, but print('after') never does. What does that mean?
Prints are how you answer "did the event even fire?" — the first question of every event bug:
clickEvent.OnServerEvent:Connect(function(player)
print("click from", player.Name)
-- ...
end)
If nothing prints, the connection never fired — wrong event, wrong name, or the script never connected. If it prints but nothing happens after, the bug is downstream. One line of print told you which half to investigate.
Before doing work, print that a click arrived and whose it was. Write the print line for the OnServerEvent callback.
clickEvent.OnServerEvent:Connect(function(player)
-- trace the click
local coins = player.leaderstats.Coins
end)Next: the classic bugs — and how to smell them coming.