My script work only one time and then just stop hatching pets. i tried removing if UsedInv.Value < Capacity.Value then and it worked but i need this check
Here is a script :
local Eggs = require(game.ReplicatedStorage.ModuleScripts.Pets)
local debounce = false
local RS = game.ReplicatedStorage
local rEvents = RS.RemoteEvents
local OpenOneSlimeEgg = rEvents.OpenOneSlimeEgg
OpenOneSlimeEgg.OnServerEvent:Connect(function(hatchplr)
local Capacity = hatchplr.MultiplierFolder.PetINVCapacity
local UsedInv = hatchplr.MultiplierFolder.UsedINVCapacity
if debounce == false then
debounce = true
if UsedInv.Value < Capacity.Value then
print(Capacity.Value)
print(UsedInv.Value)
local player = hatchplr
local function HatchEgg(plr, eggname1)
local eggName = "SlimeEgg"
local eggConfig = Eggs.GetConfig(eggName)
if not eggConfig then
print("Invalid egg name:", eggName)
return
end
local currencyName = eggConfig.Currency
local eggPrice = eggConfig.Price
print(eggPrice)
local playerData = player.leaderstats
local currencyValue = playerData[currencyName]
if currencyValue.Value >= eggPrice then
currencyValue.Value -= eggPrice
local petList = {}
for petName, petData in pairs(eggConfig.Pets) do
for _ = 1, petData.Chance do
table.insert(petList, petName)
end
end
local randomIndex = math.random(1, #petList)
local selectedPet = petList[randomIndex]
if selectedPet then
local petsFolder = player.Pets.petData
UsedInv.Value += 1
local newPet = Instance.new("BoolValue")
newPet.Name = selectedPet
newPet.Parent = petsFolder
print(player.Name .. " hatched a " .. selectedPet)
else
warn("what happened? Write to developer (EGG SYSTEM PROBLEM) "..player.UserId..eggName)
end
else
warn(player.Name .. " does not have enough " .. currencyName)
end
end
HatchEgg()
elseif debounce == true then
wait(2)
debounce = false
end
end
end)