Basically I found an egg hatching tutorial and this is the chance script; Im having trouble understanding how rare each rarity actually is. Is there any way to convert these into percentages? ( without changing the code, i just want to have
--[[
Rarities;
1K = 25%
500 = 13%
300 = 6%
100 = 3%
1 = 1%
--]]
Not those exact percentages but something along those lines
local module = {
--Demonic
["Common"] = {
["Cost"] = 500,
["Pets"] = {-- {Weight/Rarity}
["Cat"] = {1000},
["Dog"] = {1000},
["Bunny"] = {300},
["Bear"] = {300},
["Rare Pet"] = {100},
["Unobtainable Pet"] = {1},
},
}
}
return module
--[[
Rarities;
1K = Common
500 = Uncommon
300 = Uncommon
100 = Rare
1 = Extreme
--]]
and here is where the math.random is:
local function ChoosePet()
local Chance = math.random(1,TotalWeight)
local Counter = 0
for i,v in pairs(Pets) do
Counter = Counter+v[1]
if Chance <= Counter then
return i
end
end
end
here is the full script in case you need it;
local ProximityPromptService = game:GetService("ProximityPromptService")
local RS = game:GetService("ReplicatedStorage")
local Eggs = require(RS:WaitForChild("Eggs"))
local Data = Eggs[script.Name]
local Cost = Data["Cost"]
local Pets = Data["Pets"]
local Buy = game.Workspace.Eggs.Common
local Cost1 = Buy:WaitForChild("Cost")
local CD = Buy.Buy:WaitForChild("ProximityPrompt")
local CostGUI = Cost1:WaitForChild("Am")
local CostText = CostGUI:WaitForChild("TextLabel")
CostText.Text = Cost.." Coins"
local TotalWeight = 0
for i,v in pairs(Pets) do
TotalWeight = TotalWeight + v[1]
end
local function ChoosePet()
local Chance = math.random(1,TotalWeight)
local Counter = 0
for i,v in pairs(Pets) do
Counter = Counter+v[1]
if Chance <= Counter then
return i
end
end
end
CD.Triggered:Connect(function(Player)
local Stats = Player:WaitForChild("leaderstats")
local Coins = Stats:WaitForChild("Coins")
local open = Player:WaitForChild('OpenValue')
local got = Player:WaitForChild('GotPet')
if Coins.Value >= Cost then
Coins.Value = Coins.Value - Cost
open.Value = 'Open'
got.Value = ChoosePet()
local findpet = Player:WaitForChild('Pets')
local sqq = findpet:FindFirstChild(got.Value)
sqq.Value = 'owned'
wait(5)
open.Value = 'Close'
got.Value = ''
end
end)
