Before getting started
This is the fully functional shop you’ll have at the end of the tutorial, with images / backgrounds fully customizable, and with DataStores & buying with Robux and in-game currency.
If you want to skip straight to having everything working, the great news is I already made a plugin to do that, so you can just download the free plugin here
If you want to build the Shop from scratch, keep reading…
Part 2: Scripting Currency, Items, & Purchases
Step 1: Setting up the Economy (Leaderstats)
Before players can buy items from your roblox shop gui , they need money. We will use the standard Roblox “leaderstats” system so the money shows up on the player list.
-
Go to ServerScriptService .
-
Right-click → Insert Object → Script (Server Script).
-
Name it LeaderstatsScript. Paste this roblox shop gui script example :
game.Players.PlayerAdded:Connect(function(player)
-- Create the folder to hold stats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create the currency
local cash = Instance.new("IntValue")
cash.Name = "Cash" -- You can name this Gold, Coins, etc.
cash.Value = 100 -- Giving players starting money to test
cash.Parent = leaderstats
end)
This script runs every time a player joins. By creating a folder named “leaderstats,” Roblox automatically displays the “Cash” value in the top-right player list. Adding, subtracting from this
value is also how you could add / remove money from players as they play the game.
Step 2: Preparing the Item to Sell
- Assuming you don’t have a item on hand, grab a simple Sword from the Toolbox, searching under Models. The exact model doesn’t matter
-
Name the tool SomeSword.
-
Move the tool into ReplicatedStorage .
- This is so we can store the original copy of the item here, so the server can clone it and give a new copy to players whenever they buy it.
Step 3: The Purchase Shop UI
Go back to the ShopFrame we made in Part 1.
-
Add a new TextButton inside the frame. Update the text to read “Buy Sword”, or whatever makes sense for your game
-
Add a LocalScript inside that button. Name it BuySwordScript. Paste this in
local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local buyEvent = ReplicatedStorage:WaitForChild("BuyItemEvent")
-- Configuration
local itemName = "SomeSword"
button.MouseButton1Click:Connect(function()
-- Fire the event to the server asking to buy the item
buyEvent:FireServer(itemName)
end)
We also need a way for the Client (the button) to talk to the Server (the bank).
-
Go to ReplicatedStorage .
-
Right-click → Insert Object → RemoteEvent .
-
Name it BuyItemEvent. Now we just need to ensure tapping on the ImageButton kicks off the purchasing flow.
Step 4: The Server-side handling of Purchases
Now we need the server to verify the player has enough money and give them the item. This should be handled server-side so your game doesn’t get exploited. To keep the explanation simple, exploiter software can inject code into LocalScripts. If you handled the money deduction on the Client, an exploiter could simply delete the line that subtracts money, getting everything for free.
-
Go to ServerScriptService .
-
Create a new Script named ShopServerHandler.
-
Here is an example script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local buyEvent = ReplicatedStorage:WaitForChild("BuyItemEvent")
-- Price List
local itemPrices = {
["SomeSword"] = 50 -- Cost 50 Cash
}
buyEvent.OnServerEvent:Connect(function(player, itemName)
local price = itemPrices[itemName]
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats and leaderstats:FindFirstChild("Cash")
-- 1. Check if the item and currency exist
if price and cash then
-- 2. Check if player has enough money
if cash.Value >= price then
-- 3. Deduct Money
cash.Value = cash.Value - price
-- 4. Give Item
local toolInfo = ReplicatedStorage:FindFirstChild(itemName)
if toolInfo then
local newTool = toolInfo:Clone()
newTool.Parent = player.Backpack -- Put in inventory
print("Purchase Successful!")
end
else
print("Not enough money!")
end
end
end)
Awesome, now you have a simple shop where users start off with some default currency, they can show/hide the shop, and now they can purchase items, and receive items in their backpack through the Shop GUI!
Step 5: Earn Robux!
If you want to create a roblox shop gui that earns real revenue, you need MarketplaceService. Unlike in-game cash, you don’t subtract values manually. Instead, you prompt a purchase.
- Create the Developer Product ID here: https://create.roblox.com/docs/production/monetization/developer-products
- Here is example script that you should attach as a LocalScript to the button that users would tap to purchase the item.
local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local productId = 1234567 -- Replace with your Developer Product ID
script.Parent.MouseButton1Click:Connect(function()
MarketplaceService:PromptProductPurchase(player, productId)
end)
- The Server Script (Awarding the Item)
Robux purchases require a special function called ProcessReceipt. This ensures that even if the player disconnects right as they buy something, they still get their item when they rejoin.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
-- Configuration: Map your Product ID to the Item Name in ReplicatedStorage
local productRewards = {
[1234567] = "CoolSword" -- Change [1234567] to your actual Product ID
}
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- 1. Find the player who bought the item
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- If the player left, tell Roblox to try again later
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- 2. Check which product they bought
local productId = receiptInfo.ProductId
local rewardName = productRewards[productId]
if rewardName then
-- 3. Find the item in storage and clone it
local toolTemplate = game:GetService("ReplicatedStorage"):FindFirstChild(rewardName)
if toolTemplate then
local newTool = toolTemplate:Clone()
newTool.Parent = player.Backpack
-- Optional: Add it to StarterGear so they keep it after respawning
toolTemplate:Clone().Parent = player.StarterGear
print("Robux Purchase Successful: Given " .. rewardName)
end
end
-- 4. Tell Roblox the purchase is complete
return Enum.ProductPurchaseDecision.PurchaseGranted
end
With the Cash system, we used a RemoteEvent because we control the money. With Robux, Roblox controls the money. ProcessReceipt is the official, secure way Roblox tells your server, “Okay, we took the Robux, now give them the item.”
