
Shop & inventory — DataStore persistence with retry and rate limiting
A server-authoritative Roblox shop and inventory system: schema-validated DataStore persistence that recovers from a corrupted or outdated save, automatic retry with backoff, and per-player purchase rate limiting.
-- 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





