264 подписчика
-- СКРИПТ МАГАЗИНА (поместить в ServerScriptService)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Создаём RemoteEvent для связи сервера с клиентом
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "ShopRemoteEvent"
remoteEvent.Parent = ReplicatedStorage
-- === НАСТРОЙКИ МАГАЗИНА ===
local shopItems = {
{
itemName = "Зелье здоровья",
price = 50,
description = "Восстанавливает 50 HP",
icon = "rbxassetid://1234567890", -- замените на свой ID
itemType = "heal",
healAmount = 50
},
{
itemName = "Меч",
price = 150,
description = "Увеличивает урон",
icon = "rbxassetid://1234567890",
itemType = "sword"
},
{
itemName = "Ключ",
price = 100,
description = "Открывает секретную дверь",
icon = "rbxassetid://1234567890",
itemType = "key"
}
}
-- === ФУНКЦИЯ ПОКУПКИ ===
local function purchaseItem(player, itemIndex)
local item = shopItems[itemIndex]
if not item then
warn("Товар не найден")
return false
end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return false end
local money = leaderstats:FindFirstChild("Money")
if not money then return false end
if money.Value >= item.price then
-- Списываем монеты
money.Value = money.Value - item.price
-- Выдаём предмет (настраиваем под свои нужды)
giveItemToPlayer(player, item)
print(player.Name .. " купил " .. item.itemName .. " за " .. item.price .. " монет")
return true
else
print(player.Name .. " не хватает монет для покупки " .. item.itemName)
return false
end
end
-- === ФУНКЦИЯ ВЫДАЧИ ПРЕДМЕТА ===
local function giveItemToPlayer(player, item)
-- Пример: кладём предмет в Backpack или в специальный папку
if item.itemType == "heal" then
-- Восстановление здоровья
local character = player.Character
if character then
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + item.healAmount)
end
end
elseif item.itemType == "sword" then
-- Даём меч (создаём инструмент)
local tool = Instance.new("Tool")
tool.Name = item.itemName
tool.RequiresHandle = false
tool.Parent = player.Backpack
elseif item.itemType == "key" then
-- Сохраняем в IntValue, что у игрока есть ключ
local keyValue = Instance.new("BoolValue")
keyValue.Name = "HasKey"
keyValue.Value = true
keyValue.Parent = player
end
end
-- === GUI ДЛЯ КНОПКИ ОТКРЫТИЯ МАГАЗИНА ===
local function createShopButton(player)
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "ShopButtonGUI"
screenGui.Parent = player:WaitForChild("PlayerGui")
-- Кнопка открытия магазина
local openButton = Instance.new("TextButton")
openButton.Size = UDim2.new(0, 60, 0, 60)
openButton.Position = UDim2.new(1, -80, 0, 10)
openButton.BackgroundColor3 = Color3.fromRGB(255, 170, 0)
openButton.Text = "🛒"
openButton.TextSize = 30
openButton.Font = Enum.Font.GothamBold
openButton.Parent = screenGui
-- Закругление
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 30)
corner.Parent = openButton
-- Открытие магазина при нажатии
openButton.MouseButton1Click:Connect(function()
remoteEvent:FireClient(player, "openShop", shopItems)
end)
end
-- === СОЗДАНИЕ GUI МАГАЗИНА НА КЛИЕНТЕ ===
local function setupClientShop(player)
local function createShopGui(items)
-- Удаляем старый GUI, если есть
local oldGui = player.PlayerGui:FindFirstChild("ShopGUI")
if oldGui then oldGui:Destroy() end
local shopGui = Instance.new("ScreenGui")
shopGui.Name = "ShopGUI"
shopGui.Parent = player.PlayerGui
-- Фон
local background = Instance.new("Frame")
background.Size = UDim2.new(0, 400, 0, 500)
background.Position = UDim2.new(0.5, -200, 0.5, -250)
background.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
background.BackgroundTransparency = 0.1
background.BorderSizePixel = 0
background.Parent = shopGui
local cornerBg = Instance.new("UICorner")
cornerBg.CornerRadius = UDim.new(0, 15)
3 минуты
29 марта