Roblox shop script (buy items with coins)
A shop where players spend in-game Coins on tools. The server checks the price and the coins, so exploiters can't buy for free, and bought tools come back after every respawn.
ScriptUpdated November 28, 2026
Where to put it
Script — ServerScriptService > Shop (Script). It runs on the server, so players can't change what it does.
- Players need
leaderstats > Coins— the leaderboard script creates it. - In ServerStorage, make a Folder named
ShopItemsand put your Tools in it (for exampleSword,SpeedCoil). Items in ServerStorage can't be taken by clients. - Select each tool, and in Properties → Attributes click
+, add a Number attribute namedPriceand type its price. - The script creates the
BuyItemRemoteFunction in ReplicatedStorage itself. For the button, see the first variation.
The script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local items = ServerStorage:WaitForChild("ShopItems")
local buyItem = Instance.new("RemoteFunction")
buyItem.Name = "BuyItem"
buyItem.Parent = ReplicatedStorage
buyItem.OnServerInvoke = function(player, itemName)
-- Never trust what the client sends: check the type, the item and the price here.
if typeof(itemName) ~= "string" then
return false, "Unknown item"
end
local item = items:FindFirstChild(itemName)
local price = item and item:GetAttribute("Price")
if typeof(price) ~= "number" or price < 0 then
return false, "Unknown item"
end
local starterGear = player:FindFirstChild("StarterGear")
if not starterGear then
return false, "Try again"
end
if starterGear:FindFirstChild(itemName) then
return false, "You already own it"
end
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if not coins or coins.Value < price then
return false, "Not enough coins"
end
coins.Value -= price
-- StarterGear is copied into the Backpack on every respawn, so the item stays.
item:Clone().Parent = starterGear
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
item:Clone().Parent = backpack
end
return true, "Bought " .. itemName
endHow it works
- The client only sends the item's name. The price comes from the tool's
Priceattribute on the server, so an exploiter can't send “price = 0”. - A RemoteFunction returns an answer, so the button can show “Bought Sword” or “Not enough coins” without a second event.
- The check and the payment happen with no wait in between, so two fast clicks can't both pass the coin check.
Player.StarterGearis Roblox's built-in place for tools a player keeps for the session: everything in it is copied into the Backpack after each respawn. The copy in the Backpack gives the tool right away.
Variations
Buy button (LocalScript)
In StarterGui add a ScreenGui, a TextButton inside it, and this LocalScript inside the button. Change ITEM to the tool's name.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local buyItem = ReplicatedStorage:WaitForChild("BuyItem")
local ITEM = "Sword"
local button = script.Parent
local busy = false
button.Text = "Buy " .. ITEM
button.Activated:Connect(function()
if busy then
return
end
busy = true
local ok, message = buyItem:InvokeServer(ITEM)
button.Text = message
task.wait(1.5)
button.Text = ok and "Owned" or "Buy " .. ITEM
busy = false
end)Open the shop with E
Put a ProximityPrompt in a shop counter. In a LocalScript, connect prompt.Triggered and set the shop ScreenGui's Enabled to true. The event passes the player who used the prompt — check player == Players.LocalPlayer before opening the GUI.
Keep purchases after leaving
StarterGear lasts one session. To keep items forever, save a list of owned item names with a data store when the player leaves, and on join clone those items into StarterGear again.
Items for Robux
Coins are your own currency. To sell for Robux, use a game pass (owned forever) or a developer product (bought again and again) and grant the item on the server after MarketplaceService confirms the purchase.
Common mistakes
- Taking the price from the client (
BuyItem:InvokeServer("Sword", 0)): exploiters set any price they like. Read it on the server. - Removing coins in a LocalScript: the number on the leaderboard drops for that player only, and the server never charges them.
- Keeping shop tools in ReplicatedStorage: clients can see and copy anything there. Use ServerStorage.
- Giving the tool only to the Backpack: it disappears on the next respawn. Put a copy in StarterGear too.
FAQ
How do I make a shop in Roblox Studio?
Keep the items in ServerStorage with a Price attribute, create a RemoteFunction, and in a server Script check the player's coins, take the price and clone the item into their Backpack and StarterGear. A TextButton with a LocalScript calls the RemoteFunction. Both scripts are on this page.
Should a Roblox shop use a RemoteEvent or a RemoteFunction?
Either works. A RemoteFunction is simpler for a shop because the server can answer with a result such as "Not enough coins". Never let the client decide the price or change the coins.
How do I keep bought items after the player dies?
Clone the tool into Player.StarterGear as well as the Backpack. Roblox copies StarterGear into the Backpack on every respawn. To keep items after leaving the game, save them with a data store.
How do I make a shop GUI open when I touch or walk up to a part?
Use a ProximityPrompt on the shop part and, in a LocalScript, turn on the shop ScreenGui when the prompt is triggered by the local player. Touched works too, but a prompt is easier on phones.