SHOW:
|
|
- or go back to the newest paste.
1 | local players = game:GetService("Players") | |
2 | local httpService = game:GetService("HttpService") | |
3 | local replicatedStorage = game:GetService("ReplicatedStorage") | |
4 | local remotes = replicatedStorage.Remotes | |
5 | local eggs = workspace.Eggs | |
6 | local playerBusy = {} | |
7 | ||
8 | ||
9 | local function chooseRandomPet(petTable) | |
10 | local pet = nil | |
11 | local number = math.random(1,100) | |
12 | local weight = 0 | |
13 | ||
14 | for i, v in pairs(petTable) do | |
15 | weight += v.chance | |
16 | ||
17 | if weight >= number then | |
18 | pet = v | |
19 | break | |
20 | end | |
21 | end | |
22 | ||
23 | return pet | |
24 | end | |
25 | ||
26 | ||
27 | for i, egg in pairs(eggs:GetChildren()) do | |
28 | egg.ProximityPrompt.Triggered:Connect(function(player) | |
29 | local eggData = require(egg.Data) | |
30 | local price = eggData.price | |
31 | local currency = eggData.currency | |
32 | ||
33 | if player.leaderstats[currency].Value >= price then | |
34 | if not playerBusy[player] then | |
35 | playerBusy[player] = true | |
36 | local chosenPet = chooseRandomPet(eggData.pets) | |
37 | player.leaderstats[currency].Value -= price | |
38 | local pet = Instance.new("StringValue") | |
39 | pet.Name = chosenPet.model | |
40 | pet.Value = httpService:GenerateGUID() | |
41 | pet.Parent = player.Pets | |
42 | remotes.Egg:FireClient(player, pet.Name, pet.Value, egg.Name) | |
43 | task.wait(5) | |
44 | playerBusy[player] = false | |
45 | end | |
46 | end | |
47 | end) | |
48 | end | |
49 | ||
50 | ||
51 | players.PlayerRemoving:Connect(function(player) | |
52 | if playerBusy[player] then | |
53 | playerBusy[player] = nil | |
54 | end | |
55 | end) |