Skip to content

Instantly share code, notes, and snippets.

@MajorTal
Created June 4, 2025 15:18
Show Gist options
  • Save MajorTal/7cf0958477f5aaec79c315d9b7f69cbb to your computer and use it in GitHub Desktop.
Save MajorTal/7cf0958477f5aaec79c315d9b7f69cbb to your computer and use it in GitHub Desktop.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local ShopItems = require(ServerStorage.ShopItems)
local buyItemEvent = ReplicatedStorage:WaitForChild("BuyItemEvent")
buyItemEvent.OnServerEvent:Connect(function(player, itemType)
local itemDef = ShopItems[itemType]
if not itemDef then
warn("Unknown item:", itemType)
return
end
local cash = player.leaderstats.Cash
if cash.Value >= itemDef.Price then
cash.Value -= itemDef.Price
-- Give generic placement tool set to this item
local toolClone = ServerStorage.PlacementTool:Clone()
toolClone.ItemType.Value = itemType
toolClone.Parent = player.Backpack
print(player.Name .. " bought item:", itemType)
else
warn("Not enough cash for item:", itemType)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment