
Loja & inventário — persistência em DataStore com retry e rate limiting
Uma loja e inventário para Roblox com autoridade no servidor: persistência em DataStore validada por schema, que se recupera de um save corrompido ou desatualizado, retry automático com backoff, e limite de taxa de compra por jogador.
-- Server-side source of truth for prices. Never trust the client with prices.
local SHOP_CATALOG = {
SwordCommon = { price = 50, displayName = "Common Sword" },
SwordRare = { price = 200, displayName = "Rare Sword" },
PotionHeal = { price = 15, displayName = "Healing Potion" },
SpeedBoostGear = { price = 80, displayName = "Speed Boost" },
}
local function attemptPurchase(player, itemId)
local item = SHOP_CATALOG[itemId]
local data = sessionCache[player.UserId]
if not item or not data then
return false, "Invalid item or player data not loaded"
end
if data.coins < item.price then
return false, "Not enough coins"
end
data.coins -= item.price
data.inventory[itemId] = (data.inventory[itemId] or 0) + 1
return true, item.displayName
end





