game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 100
coins.Parent = leaderstats
end)local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local coins = player.leaderstats.Coins
if coins.Value >= 50 then
coins.Value = coins.Value - 50
print("Покупка успешна")
else
print("Недостаточно денег")
end
end)local event = game.ReplicatedStorage:WaitForChild("BuyItem")
script.Parent.MouseButton1Click:Connect(function()
event:FireServer("Sword")
end)local event = game.ReplicatedStorage:WaitForChild("BuyItem")
event.OnServerEvent:Connect(function(player, itemName)
local coins = player.leaderstats.Coins
if itemName == "Sword" and coins.Value >= 50 then
coins.Value -= 50
local item = game.ServerStorage:FindFirstChild("Sword")
if item then
local clone = item:Clone()
clone.Parent = player.Backpack
end
end
end)