#Rng for eggs not working right
1 messages · Page 1 of 1 (latest)
local module = {}
local MaxPets = 30
module.Hatch = function(Player: Player, Egg: Part)
if Player.Configuration.Hatching.Value == true then return end
local price = Egg.Configuration.Cost.Value
local stat = Player:FindFirstChild("leaderstats"):FindFirstChild("Coins")
if #Player.OwnedPets:GetChildren() + #Player.EquippedPets:GetChildren() >= MaxPets then
print("Pet limit reached")
return
end
if stat.Value >= price then
stat.Value -= price
local petsModule = Egg:FindFirstChild("Pets")
if not petsModule then
warn("No Pets module found in egg!")
return
end
local success, petTable = pcall(function()
return require(petsModule).Pets
end)
if not success or not petTable or type(petTable) ~= "table" then
warn("Failed to load pets table")
return
end
print("Loaded pets:", petTable)
local difference = petTable[#petTable][2]
print("Chance cap:", difference)
local random = Random.new():NextInteger(1, difference)
print("Random roll:", random)
local chosenPet = nil
local lastNumber = 0
for _, v in pairs(petTable) do
if random > lastNumber then
chosenPet = v[1]
lastNumber = v[2]
else
break
end
end
print("Chosen pet:", chosenPet)
game.ReplicatedStorage.Remotes.EggAnimation:FireClient(Player, Egg, chosenPet)
local folder = Player:FindFirstChild("OwnedPets")
if folder and chosenPet then
local tag = Instance.new("IntValue")
tag.Name = chosenPet
tag.Parent = folder
end
else
print("Not enough cash!")
end
end
return module
local module = {}
module.Pets = {
{"Black Cat", 128},
{"White Cat", 64},
{"Grey Cat", 32},
{"Red Cat", 16},
{"Blue Cat", 8},
{"Green Cat", 4},
{"Purple Cat", 2},
{"Shiny Cat", 1},
}
return module
also one thing is there anyway where i can change the second module script so that the shiny cat instead of making the value 1 which means the rareist make it so that if i put 1000 that would mean there is a 1 in 1000 chance of getting the shiny cat?
19:40:19.153 Chance cap: 1 - Server - EggModules:36
19:40:19.153 Random roll: 1 - Server - EggModules:39
19:40:19.154 Chosen pet: Black Cat - Server - EggModules:52```
this is what its showing
In the Pets table theres a comma at the last one that you dont need
yeah but that doesn't change the result therefore it doesn't matter