local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local ShopFunction = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ShopFunction") local RedeemCodeFunc = ReplicatedStorage:WaitForChild("Events"):WaitForChild("RedeemCode") local AbilitiesFolder = ReplicatedStorage:WaitForChild("Abilities") -- НАСТРОЙКИ НАГРАД local COINS_PER_KILL = 75 local TIME_REWARD = 85 local TIME_INTERVAL = 600 -- 10 минут в секундах (60 * 10) -- КОДЫ (Код = Сумма) local VALID_CODES = { ["START"] = 500, ["MAGIC"] = 1000, ["TEST"] = 100 } -- Таблица использованных кодов (в реальной игре нужно DataStore) local usedCodesSession = {} print("💰 Экономика запущена") -- === 1. ИНИЦИАЛИЗАЦИЯ ИГРОКА === 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 = 0 -- Стартовые деньги coins.Parent = leaderstats -- Папка для купленных способностей local ownedFolder = Instance.new("Folder") ownedFolder.Name = "OwnedAbilities" ownedFolder.Parent = player -- Выдаем бесплатные способности сразу for _, module in pairs(AbilitiesFolder:GetChildren()) do local data = require(module) if data.Info.IsDefault then local tag = Instance.new("StringValue") tag.Name = module.Name tag.Parent = ownedFolder end end -- Запускаем таймер на 10 минут task.spawn(function() while player do task.wait(TIME_INTERVAL) if player then player.leaderstats.Coins.Value += TIME_REWARD -- Можно отправить уведомление клиенту, что пришли деньги end end end) end) -- === 2. ПОКУПКА СПОСОБНОСТЕЙ === ShopFunction.OnServerInvoke = function(player, abilityName) local coins = player.leaderstats.Coins local ownedFolder = player.OwnedAbilities -- Проверка: существует ли такая способность? local moduleScript = AbilitiesFolder:FindFirstChild(abilityName) if not moduleScript then return "Error" end local moduleData = require(moduleScript) local price = moduleData.Info.Price or 0 -- Проверка: уже куплено? if ownedFolder:FindFirstChild(abilityName) then return "AlreadyOwned" end -- Проверка: хватает ли денег? if coins.Value >= price then coins.Value -= price -- Забираем деньги -- Выдаем способность local tag = Instance.new("StringValue") tag.Name = abilityName tag.Parent = ownedFolder return "Success" else return "NoMoney" end end -- === 3. СИСТЕМА КОДОВ === RedeemCodeFunc.OnServerInvoke = function(player, code) -- Проверяем, использовал ли игрок этот код (в этой сессии) if not usedCodesSession[player.UserId] then usedCodesSession[player.UserId] = {} end if usedCodesSession[player.UserId][code] then return "Used" end local reward = VALID_CODES[code] if reward then player.leaderstats.Coins.Value += reward usedCodesSession[player.UserId][code] = true return "Success", reward else return "Invalid" end end -- === 4. НАГРАДА ЗА УБИЙСТВО === -- Для этого нам нужно ловить момент смерти. -- Лучший способ: когда CombatServer наносит урон, проверять, умер ли враг. -- Но чтобы не усложнять CombatServer, сделаем глобальный трекер здесь. game.Workspace.DescendantAdded:Connect(function(descendant) if descendant:IsA("Humanoid") then descendant.Died:Connect(function() -- Ищем тег "creator" (стандарт Роблокса для определения убийцы) local creatorTag = descendant:FindFirstChild("creator") if creatorTag and creatorTag.Value then local killerPlayer = creatorTag.Value if killerPlayer:IsA("Player") then killerPlayer.leaderstats.Coins.Value += COINS_PER_KILL end end end) end end)