Guest

Roblox Game Script for Player Scoring and Economy

Nov 22nd, 2025
118
0
Never
Not a member of gistpad yet? Sign Up, it unlocks many cool features!
Lua 20.14 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local ShopFunction = ReplicatedStorage:WaitForChild("Events"):WaitForChild("ShopFunction")
  4. local RedeemCodeFunc = ReplicatedStorage:WaitForChild("Events"):WaitForChild("RedeemCode")
  5. local AbilitiesFolder = ReplicatedStorage:WaitForChild("Abilities")
  6.  
  7. -- НАСТРОЙКИ НАГРАД
  8. local COINS_PER_KILL = 75
  9. local TIME_REWARD = 85
  10. local TIME_INTERVAL = 600 -- 10 минут в секундах (60 * 10)
  11.  
  12. -- КОДЫ (Код = Сумма)
  13. local VALID_CODES = {
  14. ["START"] = 500,
  15. ["MAGIC"] = 1000,
  16. ["TEST"] = 100
  17. }
  18.  
  19. -- Таблица использованных кодов (в реальной игре нужно DataStore)
  20. local usedCodesSession = {}
  21.  
  22. print("💰 Экономика запущена")
  23.  
  24. -- === 1. ИНИЦИАЛИЗАЦИЯ ИГРОКА ===
  25. Players.PlayerAdded:Connect(function(player)
  26. -- Создаем папку лидерстатов (чтобы висела таблица справа сверху)
  27. local leaderstats = Instance.new("Folder")
  28. leaderstats.Name = "leaderstats"
  29. leaderstats.Parent = player
  30.  
  31. local coins = Instance.new("IntValue")
  32. coins.Name = "Coins"
  33. coins.Value = 0 -- Стартовые деньги
  34. coins.Parent = leaderstats
  35.  
  36. -- Папка для купленных способностей
  37. local ownedFolder = Instance.new("Folder")
  38. ownedFolder.Name = "OwnedAbilities"
  39. ownedFolder.Parent = player
  40.  
  41. -- Выдаем бесплатные способности сразу
  42. for _, module in pairs(AbilitiesFolder:GetChildren()) do
  43. local data = require(module)
  44. if data.Info.IsDefault then
  45. local tag = Instance.new("StringValue")
  46. tag.Name = module.Name
  47. tag.Parent = ownedFolder
  48. end
  49. end
  50.  
  51. -- Запускаем таймер на 10 минут
  52. task.spawn(function()
  53. while player do
  54. task.wait(TIME_INTERVAL)
  55. if player then
  56. player.leaderstats.Coins.Value += TIME_REWARD
  57. -- Можно отправить уведомление клиенту, что пришли деньги
  58. end
  59. end
  60. end)
  61. end)
  62.  
  63. -- === 2. ПОКУПКА СПОСОБНОСТЕЙ ===
  64. ShopFunction.OnServerInvoke = function(player, abilityName)
  65. local coins = player.leaderstats.Coins
  66. local ownedFolder = player.OwnedAbilities
  67.  
  68. -- Проверка: существует ли такая способность?
  69. local moduleScript = AbilitiesFolder:FindFirstChild(abilityName)
  70. if not moduleScript then return "Error" end
  71.  
  72. local moduleData = require(moduleScript)
  73. local price = moduleData.Info.Price or 0
  74.  
  75. -- Проверка: уже куплено?
  76. if ownedFolder:FindFirstChild(abilityName) then
  77. return "AlreadyOwned"
  78. end
  79.  
  80. -- Проверка: хватает ли денег?
  81. if coins.Value >= price then
  82. coins.Value -= price -- Забираем деньги
  83.  
  84. -- Выдаем способность
  85. local tag = Instance.new("StringValue")
  86. tag.Name = abilityName
  87. tag.Parent = ownedFolder
  88.  
  89. return "Success"
  90. else
  91. return "NoMoney"
  92. end
  93. end
  94.  
  95. -- === 3. СИСТЕМА КОДОВ ===
  96. RedeemCodeFunc.OnServerInvoke = function(player, code)
  97. -- Проверяем, использовал ли игрок этот код (в этой сессии)
  98. if not usedCodesSession[player.UserId] then usedCodesSession[player.UserId] = {} end
  99.  
  100. if usedCodesSession[player.UserId][code] then
  101. return "Used"
  102. end
  103.  
  104. local reward = VALID_CODES[code]
  105.  
  106. if reward then
  107. player.leaderstats.Coins.Value += reward
  108. usedCodesSession[player.UserId][code] = true
  109. return "Success", reward
  110. else
  111. return "Invalid"
  112. end
  113. end
  114.  
  115. -- === 4. НАГРАДА ЗА УБИЙСТВО ===
  116. -- Для этого нам нужно ловить момент смерти.
  117. -- Лучший способ: когда CombatServer наносит урон, проверять, умер ли враг.
  118. -- Но чтобы не усложнять CombatServer, сделаем глобальный трекер здесь.
  119.  
  120. game.Workspace.DescendantAdded:Connect(function(descendant)
  121. if descendant:IsA("Humanoid") then
  122. descendant.Died:Connect(function()
  123. -- Ищем тег "creator" (стандарт Роблокса для определения убийцы)
  124. local creatorTag = descendant:FindFirstChild("creator")
  125. if creatorTag and creatorTag.Value then
  126. local killerPlayer = creatorTag.Value
  127. if killerPlayer:IsA("Player") then
  128. killerPlayer.leaderstats.Coins.Value += COINS_PER_KILL
  129. end
  130. end
  131. end)
  132. end
  133. end)
RAW Gist Data Copied