Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local players = game:GetService("Players")
- local httpService = game:GetService("HttpService")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local remotes = replicatedStorage.Remotes
- local eggs = workspace.Eggs
- local playerBusy = {}
- local function chooseRandomPet(petTable)
- local pet = nil
- local number = math.random(1,100)
- local weight = 0
- for i, v in pairs(petTable) do
- weight += v.chance
- if weight >= number then
- pet = v
- break
- end
- end
- return pet
- end
- for i, egg in pairs(eggs:GetChildren()) do
- egg.ProximityPrompt.Triggered:Connect(function(player)
- local eggData = require(egg.Data)
- local price = eggData.price
- local currency = eggData.currency
- if player.leaderstats[currency].Value >= price then
- if not playerBusy[player] then
- playerBusy[player] = true
- local chosenPet = chooseRandomPet(eggData.pets)
- player.leaderstats[currency].Value -= price
- local pet = Instance.new("StringValue")
- pet.Name = chosenPet.model
- pet.Value = httpService:GenerateGUID()
- pet.Parent = player.Pets
- remotes.Egg:FireClient(player, pet.Name, pet.Value, egg.Name)
- task.wait(5)
- playerBusy[player] = false
- end
- end
- end)
- end
- players.PlayerRemoving:Connect(function(player)
- if playerBusy[player] then
- playerBusy[player] = nil
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement