โ† Back to all scripts

Shop System

Buy items with in-game cash via RemoteEvent. Server validates every purchase.

EconomyIntermediateServerScriptService + LocalScript
shop-system.lua
-- Shop System
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage     = game:GetService("ServerStorage")
local ITEMS = {
    Sword  = { price = 50  },
    Shield = { price = 100 },
}
local buyEvent = Instance.new("RemoteEvent")
buyEvent.Name = "BuyItem"
buyEvent.Parent = ReplicatedStorage

buyEvent.OnServerEvent:Connect(function(player, itemId)
    local item = ITEMS[itemId]
    if not item then return end
    local cash = player.leaderstats and player.leaderstats:FindFirstChild("Cash")
    if not cash or cash.Value < item.price then return end
    local tool = ServerStorage:FindFirstChild(itemId)
    if not tool then return end
    cash.Value -= item.price
    tool:Clone().Parent = player.Backpack
end)

-- CLIENT: buyEvent:FireServer("Sword")
Related scripts in Economy
Give Cash on KillBeginner โ†’Inventory SystemIntermediate โ†’
Something broken or not working?
๐Ÿ”ง Try the AI Script Fixer โ†’