Advertisement
Cakey3101

Egg System Server

May 13th, 2025
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local ServerStorage = game:GetService("ServerStorage")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local MarketPlaceService = game:GetService("MarketplaceService")
  5. local DataStoreService = game:GetService("DataStoreService")
  6.  
  7. local DataStore = DataStoreService:GetDataStore("EggsSystem1")
  8.  
  9. local function PlayerAdded(Player: Player)
  10.     for i, v in pairs(ServerStorage.EggHatchingData:GetChildren()) do
  11.         v:Clone().Parent = Player
  12.     end
  13.  
  14.     if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 1209923362) then
  15.         Player.Values:FindFirstChild("CanTripleHatch").Value = true
  16.     end
  17.  
  18.     local Data = DataStore:GetAsync(Player.UserId.."Chaos")
  19.  
  20.     if Data ~= nil then
  21.         for i, v in pairs(Data) do
  22.             local Val = Instance.new("StringValue", Player.Chaos)
  23.             Val.Name = v
  24.         end
  25.     end
  26. end
  27.  
  28. local function PlayerRemoving(Player: Player)
  29.     local Chaos = {}
  30.  
  31.     for i, v in pairs(Player.Chaos:GetChildren()) do
  32.         table.insert(Chaos, v.Name)
  33.     end
  34.  
  35.     DataStore:SetAsync(Player.UserId.."Chaos", Chaos)
  36. end
  37.  
  38. local function ChooseChao(Egg)
  39.     local Chance = math.random(1, 100)
  40.     local Counter = 0
  41.     for _, Chao in pairs(ReplicatedStorage.Chaos[Egg.Name]:GetChildren()) do
  42.         Counter = Counter + Chao.Rarity.Value
  43.         if Chance <= Counter then
  44.             return Chao.Name
  45.         end
  46.     end
  47. end
  48.  
  49. ReplicatedStorage.Remotes.Chaos.HatchServer.OnServerInvoke = function(Player, Egg)
  50.     local EggModel = workspace.Eggs:FindFirstChild(Egg.Name)
  51.     if EggModel ~= nil then
  52.         local Price = EggModel:FindFirstChild("Price")
  53.         local Currency = EggModel:FindFirstChild("Currency").Value
  54.         local NumberPrice = tonumber(Price.Value)
  55.  
  56.         if tonumber(Player.leaderstats[Currency].Value) >= NumberPrice then
  57.             Player.leaderstats[Currency].Value -= Price.Value
  58.             local ChosenChao = ChooseChao(Egg)
  59.             local Val = Instance.new("StringValue", Player.Chaos)
  60.             Val.Name = ChosenChao
  61.  
  62.             print(ChosenChao)
  63.  
  64.             return ChosenChao
  65.         else
  66.             return "Cannot Hatch"
  67.         end
  68.     end
  69. end
  70.  
  71. ReplicatedStorage.Remotes.Chaos.Hatch3Chaos.OnServerInvoke = function(Player, Egg)
  72.     if Player.Values.CanTripleHatch.Value == true then
  73.         local EggModel = workspace.Eggs:FindFirstChild(Egg.Name)
  74.         if EggModel ~= nil then
  75.             local Price = EggModel:FindFirstChild("Price")
  76.             local Currency = EggModel:FindFirstChild("Currency").Value
  77.             local NumberPrice = tonumber(Price.Value)
  78.  
  79.             if tonumber(Player.leaderstats[Currency].Value) >= NumberPrice * 3 then
  80.                 Player.leaderstats[Currency].Value -= NumberPrice * 3
  81.                 local ChosenChao = ChooseChao(Egg)
  82.                 local ChosenChao2 = ChooseChao(Egg)
  83.                 local ChosenChao3 = ChooseChao(Egg)
  84.  
  85.                 local Val = Instance.new("StringValue", Player.Chaos)
  86.                 Val.Name = ChosenChao
  87.  
  88.                 local Val2 = Instance.new("StringValue", Player.Chaos)
  89.                 Val2.Name = ChosenChao2
  90.  
  91.                 local Val3 = Instance.new("StringValue", Player.Chaos)
  92.                 Val3.Name = ChosenChao3
  93.  
  94.                 print(ChosenChao)
  95.                 print(ChosenChao2)
  96.                 print(ChosenChao3)
  97.  
  98.                 return ChosenChao, ChosenChao2, ChosenChao3
  99.             else
  100.                 return false
  101.             end
  102.         end
  103.     else
  104.         return "The Player Does Not Own The Gamepass"
  105.     end
  106. end
  107.  
  108. ReplicatedStorage.Remotes.Chaos.EquipChao.OnServerInvoke = function(Player, ChaoName)
  109.     local EquippedNumberOfChaos = #workspace.PlayerChaos:FindFirstChild(Player.Name):GetChildren()
  110.  
  111.     if (EquippedNumberOfChaos + 1) <= Player.Values.MaxChaosEquipped.Value then
  112.         local ClonedChao = ReplicatedStorage.Chaos:FindFirstChild(ChaoName, true):Clone()
  113.         ClonedChao.Parent = workspace.PlayerChaos:FindFirstChild(Player.Name)
  114.  
  115.         Player.RingMultiplier.Value += ClonedChao.RingMultiplier.Value
  116.  
  117.         return "Equip"
  118.     elseif (EquippedNumberOfChaos + 1) >= Player.Values.MaxChaosEquipped.Value then
  119.         return "Cannot Equip"
  120.     end
  121. end
  122.  
  123. ReplicatedStorage.Remotes.Chaos.UnequipChao.OnServerInvoke = function(Player, ChaoName)
  124.     local Chao = workspace.PlayerChaos:FindFirstChild(Player.Name):FindFirstChild(ChaoName)
  125.  
  126.     if Player.RingMultiplier.Value == Chao.RingMultiplier.Value then
  127.         Player.RingMultiplier.Value = 1
  128.     else
  129.         Player.RingMultiplier.Value -= Chao.RingMultiplier.Value
  130.     end
  131.  
  132.     Chao:Destroy()
  133.  
  134.     return true
  135. end
  136.  
  137. ReplicatedStorage.Remotes.Chaos.DeleteChao.OnServerEvent:Connect(function(Player, ChaoName)
  138.     if Player.Chaos:FindFirstChild(ChaoName) then
  139.         Player.Chaos:FindFirstChild(ChaoName):Destroy()
  140.  
  141.         local Chao = workspace.PlayerChaos:FindFirstChild(Player.Name):FindFirstChild(ChaoName)
  142.  
  143.         if Chao ~= nil then
  144.             if Player.RingMultiplier.Value == Chao.RingMultiplier.Value then
  145.                 Player.RingMultiplier.Value = 1
  146.             else
  147.                 Player.RingMultiplier.Value -= Chao.RingMultiplier.Value
  148.             end
  149.  
  150.             Chao:Destroy()
  151.         end
  152.     end
  153. end)
  154.  
  155. MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(Player: Instance, GamepassId: number, WasPurchased: boolean)
  156.     if GamepassId == 1209923362 and WasPurchased == true then
  157.         Player.Values:FindFirstChild("CanTripleHatch").Value = true
  158.     end
  159. end)
  160.  
  161. Players.PlayerAdded:Connect(PlayerAdded)
  162. Players.PlayerRemoving:Connect(PlayerRemoving)
  163.  
  164. for i, Player in pairs(Players:GetPlayers()) do
  165.     PlayerAdded(Player)
  166. end
Tags: robloxstudio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement