Egg System Problem

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)



Hello, can you get deeper in the problem? What is the size of u capacity and etc. Any errors or try to put some print checks to see which line doesn’t work but has to

Hi capacity is 30. looking like problem is on a debounce because it isnt making to false

i tried

local function makedebouncefalse()
	wait(2)
	debounce = false
end

and it worked but so unstable like if i click so much times it will just ignore "if debounce == false "check

fixed (just changed the lines)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.