Advertisement
BOT_Script

Untitled

Nov 26th, 2022
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local Workspace = game:GetService("Workspace")
  3. local Players = game:GetService("Players")
  4. local Player = Players.LocalPlayer
  5. local TS = game:GetService("TweenService")
  6.  
  7. local PetModels = ReplicatedStorage.Pets
  8.  
  9. local EggsFolder = workspace.Eggs
  10.  
  11. local EggsConfig = require(ReplicatedStorage.Config.Eggs)
  12.  
  13. local BuyEgg = ReplicatedStorage.Remotes.BuyEgg
  14. local PetHatched = ReplicatedStorage.Remotes.PetHatched
  15.  
  16. local HATCH_COOLDOWN = 2
  17.  
  18. local HatchCooldown = {}
  19.  
  20. local test = false
  21.  
  22. local function ChoosePet(pets: table)
  23.     local totalWeight = 0
  24.     for _, pet in ipairs(pets) do
  25.         totalWeight += pet.Chance
  26.     end
  27.    
  28.     local chance = math.random(1, totalWeight)
  29.     local counter = 0
  30.     for _, pet in ipairs(pets) do
  31.         counter += pet.Chance
  32.         if chance <= counter then
  33.             return pet
  34.         end
  35.     end
  36. end
  37.  
  38.  
  39.  
  40. local function AutoHatch(player: Player, eggId: string)
  41.  
  42.     local eggConfig = EggsConfig[eggId]
  43.     local playerBalance = player.leaderstats.Coins.Value
  44.  
  45.     if playerBalance < eggConfig.Price then return end
  46.  
  47.     player.leaderstats.Coins.Value -= eggConfig.Price
  48.     local pet = ChoosePet(eggConfig.Pets)
  49.     PetHatched:FireClient(player, pet)
  50.  
  51. end
  52.  
  53.  
  54. local function Hatch(player: Player, eggId: string)
  55.     if HatchCooldown[player.UserId] then return end
  56.    
  57.    
  58.     local eggConfig = EggsConfig[eggId]
  59.     local playerBalance = player.leaderstats.Coins.Value
  60.    
  61.     if playerBalance < eggConfig.Price then return end
  62.     HatchCooldown[player.UserId] = true
  63.    
  64.     player.leaderstats.Coins.Value -= eggConfig.Price
  65.     local pet = ChoosePet(eggConfig.Pets)
  66.     PetHatched:FireClient(player, pet)
  67.        
  68.     task.delay(HATCH_COOLDOWN, function()
  69.         HatchCooldown[player.UserId] = nil
  70.     end)
  71.    
  72. end
  73.  
  74. local function Hatchx3(player: Player, eggId: string)
  75.     if HatchCooldown[player.UserId] then return end
  76.  
  77.     local eggConfig = EggsConfig[eggId]
  78.     local playerBalance = player.leaderstats.Coins.Value
  79.  
  80.     if playerBalance < eggConfig.Price then return end
  81.     HatchCooldown[player.UserId] = true
  82.    
  83.     player.leaderstats.Coins.Value -= eggConfig.Price
  84.     for i = 1, 3 do
  85.         local pet = ChoosePet(eggConfig.Pets)
  86.         PetHatched:FireClient(player, pet)
  87.     end
  88.     task.delay(HATCH_COOLDOWN, function()
  89.         HatchCooldown[player.UserId] = nil
  90.     end)
  91. end
  92.  
  93. local function CanHatch(player: Player, eggId: string)
  94.     local eggConfig = EggsConfig[eggId]
  95.     if not eggConfig then return false end
  96.    
  97.     local playerBalance = player.leaderstats.Coins.Value
  98.     return playerBalance >= eggConfig.Price
  99. end
  100.  
  101. BuyEgg.OnServerEvent:Connect(function(player: Player, eggId: string, action: string)
  102.     if not CanHatch(player, eggId) then return end
  103.    
  104.     if action == "Auto" then
  105.         AutoHatch(player, eggId)
  106.     elseif action == "x3" then
  107.         Hatchx3(player, eggId)
  108.     else
  109.         Hatch(player, eggId)
  110.     end
  111. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement