Egg Hatching System Bug

Hi, i was making a Robux egg system when i found this bug:


Now i was lucky and i hatched all the same pet, but the problem is that every time i open the egg i open + 1. So the first time is good but the second time i hatch twice and the third time i hatch tre eggs.

This is the script:

	elseif EggData["Currency"] == "Robux" then
		warn("You Need Robux")
		local userId = Player.UserId
		local EggId = DevProduct[Egg].Value
		MarketPlaceService:PromptProductPurchase(Player, DevProduct[Egg].Value)
		MarketPlaceService.PromptProductPurchaseFinished:Connect(function(userId, EggId, didPlayerPurchase)
			if didPlayerPurchase == true then
				local TotalPets = totalPets(Player)
				if TotalPets < Player.PlayerStats.MaxStorage.Value then
					Player.leaderstats.Eggs.Value = Player.leaderstats.Eggs.Value + 1
					UnBoxPet(Player, Egg, 0)
					RemoteEvents.ChangePetsValue:FireClient(Player, "TotalPets")
					wait(1)
				end
			end
		end)
	end

Can anyone help me?

1 Like

Correct me if I’m wrong, but the error would most likely be caused from either the totalPets function, or the other end of the ChangepetsValue remote event

No i dont think so because if the currency is the coins everything work perfect.I think that the problem js the PromptPriductPuurchasedFinished because detect the purchased made before, but i dont know how to fix it

It looks like you are connecting the purchase handler every time you prompt a purchase. This means that if you prompt n purchases, this will run n times, which matches with what is happening. Try moving it out from within whatever thing you have there, so that it is only connected once. Alternatively, change :Connect() to :Once(). Should also do the trick.

I used :Once() and now works thanks!

1 Like

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