Problem with robux egg

Hi devs, i wanted to do a robux egg for my game, but it’s not working…

When i buy the egg, after the PurchaseGranted the game should give me the pet with its hatching animation, but it is not working.

This is the script:

local function Hatch(player: Player, eggId: string)
	if HatchCooldown[player.UserId] then return end
	
	local eggConfig = EggsConfig[eggId]
	local playerBalance = player.leaderstats.Coins.Value
	
	if eggConfig.Robux == true then
		local pet = ChoosePet(eggConfig.Pets)
		local petInstance = Rewards.Pet(player, pet.ID, pet.Rarity)
		
		PetHatched:FireClient(player, pet, petInstance)
		EggAnimation:FireClient(player, pet, eggId)
		
		task.delay(HATCH_COOLDOWN, function()
			HatchCooldown[player.UserId] = nil
		end)
	else 
		if playerBalance < eggConfig.Price then return end
		HatchCooldown[player.UserId] = true

		player.leaderstats.Coins.Value -= eggConfig.Price
	
		local pet = ChoosePet(eggConfig.Pets)
		local petInstance = Rewards.Pet(player, pet.ID, pet.Rarity)
		
		PetHatched:FireClient(player, pet, petInstance)
		EggAnimation:FireClient(player, pet, eggId)
	
		task.delay(HATCH_COOLDOWN, function()
			HatchCooldown[player.UserId] = nil	
		end)
	end
end

local function PremiumEgg(player: Player, eggId: string)
	MarketPlaceService:PromptProductPurchase(player, devProductID)

	MarketPlaceService.PromptProductPurchaseFinished:Connect(function(player, id, purchased)
		if id == devProductID and purchased then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end)
end

local function CanHatch(player: Player, eggId: string)
	local eggConfig = EggsConfig[eggId]
	
	if not eggConfig then return false end
	if not CanStorePet(player) then return end

	if eggConfig.Robux == true then
		if PremiumEgg(player, eggId) then 
			return true
		end
	else
		local playerBalance = player.leaderstats.Coins.Value
		return playerBalance >= eggConfig.Price
		end
end

Thanks!

1 Like