- Home
- Skills
- Game Development
- Roblox Purchases, DataStores and Remotes (Luau)
Roblox Purchases, DataStores and Remotes (Luau)
Robux purchases that are never lost or duplicated, DataStores that don't drop progress, and remotes exploiters can't abuse.
Free
Works with the AI Agents you already use
Roblox Purchases, DataStores and Remotes (Luau)
Example session with this skill installed
Write the server-side ProcessReceipt for a Roblox developer product 98765 that gives 100 coins. Players data is saved with DataStores.
- Read your context and instructions
- Compiled the roblox purchases datastores
-- ServerScriptService/PurchaseHandler (Script)
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerStore = DataStoreService:GetDataStore("PlayerData_v1")
local COINS_PRODUCT_ID = 98765
local COINS_AMOUNT = 100
local MAX_RECEIPTS = 100 -- how many recent PurchaseIds to remember per player
local DEFAULT_DATA = { Coins = 0, Receipts = {} }
-- In-memory session cache: [userId] = data table
-- (your load-on-join / save-on-leave code should read and write this same table)
local cache = {}
local function loadData(player)
local key = "Player_" .. player.UserId
local ok, data = pcall(function()
return PlayerStore:GetAsync(key)
end)
if not ok then
warn("Load failed for", player.Name, data)
return
end
data = data or {}
data.Coins = data.Coins or DEFAULT_DATA.Coins
data.Receipts = data.Receipts or {}
cache[player.UserId] = data
end
-- Saves via UpdateAsync, merging with what's stored. Receipts are unioned so
-- a save can never "forget" a purchase that was already persisted.
local function saveData(userId)
local data = cache[userId]
if not data then return false end
local key = "Player_" .. userId
local ok, err = pcall(function()
PlayerStore:UpdateAsync(key, function(old)
old = old or {}
local merged = {}
for _, id in ipairs(old.Receipts or {}) do table.insert(merged, id) end
local seen = {}
for _, id in ipairs(merged) do seen[id] = true end
for _, id in ipairs(data.Receipts) do
if not seen[id] then table.insert(merged, id) end
end
while #merged > MAX_RECEIPTS do table.remove(merged, 1) end
return { Coins = data.Coins, Receipts = merged }
end)
end)
if not ok then warn("Save failed for", userId, err) end
return ok
end
local function hasReceipt(data, purchaseId)
return table.find(data.Receipts, purchaseId) ~= nil
end
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- Player left; Roblox will call again when they rejoin.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local data = cache[player.UserId]
if not data then
return Enum.ProductPurchaseDecision.NotProcessedYet -- data not loaded yet
end
local purchaseId = receiptInfo.PurchaseId
-- Already granted (and persisted) earlier: don't grant twice.
if hasReceipt(data, purchaseId) then
return saveData(player.UserId)
and Enum.ProductPurchaseDecision.PurchaseGranted
or Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId ~= COINS_PRODUCT_ID then
warn("Unknown product:", receiptInfo.ProductId)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Grant in memory, record the receipt, then persist.
data.Coins += COINS_AMOUNT
table.insert(data.Receipts, purchaseId)
while #data.Receipts > MAX_RECEIPTS do table.remove(data.Receipts, 1) end
if not saveData(player.UserId) then
-- Roll back so the retry doesn't double-grant.
data.Coins -= COINS_AMOUNT
table.remove(data.Receipts, table.find(data.Receipts, purchaseId))
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Optional: reflect on leaderstats
local stats = player:FindFirstChild("leaderstats")
local coins = stats and stats:FindFirstChild("Coins")
if coins then coins.Value = data.Coins end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- Must be set from exactly one server Script.
MarketplaceService.ProcessReceipt = processReceipt
Players.PlayerAdded:Connect(loadData)
for _, p in ipairs(Players:GetPlayers()) do task.spawn(loadData, p) end
Players.PlayerRemoving:Connect(function(player)
saveData(player.UserId)
cache[player.UserId] = nil
end)
game:BindToClose(function()
for userId in pairs(cache) do saveData(userId) end
end)
How it works
No double-grants. Each PurchaseId is stored in the player's data, and the coins and receipt are saved together in one record. If Roblox retries a receipt, the code sees the ID and doesn't grant again.
PurchaseGranted only after a successful save. If UpdateAsync fails, the code rolls back the in-memory change and returns NotProcessedYet. Roblox retries later, so the player isn't charged without getting coins.
NotProcessedYet for missing data. This covers a player who left or whose data hasn't loaded. Roblox re-fires the receipt when they rejoin.
UpdateAsyncmerges receipts. A later autosave can't erase a purchase that was already persisted.
Integration notes
- This is a self-contained example. If you already have a data module, delete
loadData,saveDataandcache. Keep the receipt logic, and make sure theReceiptslist is part of what you save. - Only one script may assign
ProcessReceipt. - Prompt the purchase from the client with
MarketplaceService:PromptProductPurchase(player, 98765). - Use a real Studio test with a published place. Developer product purchases don't work in an unpublished place.
Real output from a Claude Code session with this skill installed.
Connects securely to your tools. The creator never sees your data.
About this skill
Roblox games often suffer from "transaction dropped" reports and data loss due to incorrect Luau implementations. This skill provides the server-authoritative logic required to handle Robux purchases, persistent player data, and network security without the typical pitfalls of race conditions or exploitable remotes.
What it does
- Developer product handling implement
ProcessReceiptwith idempotency to prevent duplicate grants and Robux loss. - DataStore persistence manage player progress with
UpdateAsync, retries and session-locking guidance (or a maintained module such as ProfileStore) to prevent overwrites. - Remote security harden
RemoteEventswith server-side validation, type checking, and rate limiting. - Game pass verification check ownership via
UserOwnsGamePassAsyncwrapped in error handling to ensure reliability. - Shutdown protection integrate
BindToCloseand autosaves so data survives normal server shutdowns (a hard crash can still lose the last few minutes since the previous autosave).
How it works
- Purchase Integration define a dispatch table for ProductIds and hook into the global
ProcessReceiptcallback. - Data Modeling structure Luau tables for serializable storage, including versioning and purchase history tracking.
- Remote Hardening audit client-to-server calls to verify item IDs, costs, and player distances.
- Failure Testing simulate Studio environments to verify purchase retries when DataStores are unavailable.
Frameworks & tools
Specifically designed for Roblox Studio and Luau. Compatible with standard DataStoreService, MarketplaceService, and third-party modules like ProfileStore.
Why this beats prompting it yourself
Generic AI often forgets that ProcessReceipt is a singleton or suggests insecure client-side ownership checks. This skill enforces idempotency and server-side authority, so a failed save is retried instead of losing a purchase.
Use cases
- Adding coins or temporary boosts that must be granted even if a player crashes.
- Building a global inventory system that saves progress across different game servers.
- Protecting a shop system from exploiters trying to buy items for zero cost.
- Debugging "missing item" reports by implementing purchase ID logging.
Known limitations
Does not support mixed-type keys in DataStore dictionaries. Requires manual setup of ProductIds within the Roblox Creator Dashboard.
Requires manual ProductId setup in Creator Dashboard. DataStore values must be serializable (no Instances or functions). Logic is server-side only.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed 16 days ago
- Free with an Agensi account
Requires