i need help it gives me the egg even when i didn’t press purchase and i clicked decline
i searched it up everything i cant figure it out
local marketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local dataStoreService = game:GetService(“DataStoreService”)
local dataStore = dataStoreService:GetDataStore(“PetsDataStore_123”)
local EggRemoteEvents = ReplicatedStorage:WaitForChild(“EggRemoteEvents”)
local Eggs = require(ReplicatedStorage:WaitForChild(“Eggs”):WaitForChild(“ModuleScript”))local function choosePet(player, eggName)
local lucky = player:WaitForChild(“Values”):WaitForChild(“Lucky”)if lucky.Value == 2 then
local Module = Eggs[eggName]
local Pets = Module[“Pets”]local TotalWeight = 0 for i,pet in pairs(Pets) do TotalWeight += pet[3] end local Chance = math.random(1,TotalWeight) local Counter = tonumber(0) for _,pet in pairs(Pets) do Counter += tonumber(pet[3]) if Chance <= Counter then return pet else end end
elseif lucky.Value == 1 then
local Module = Eggs[eggName]
local Pets = Module[“Pets”]local TotalWeight = 0 for i,pet in pairs(Pets) do TotalWeight += pet[2] end local Chance = math.random(1,TotalWeight) local Counter = tonumber(0) for _,pet in pairs(Pets) do Counter += tonumber(pet[2]) if Chance <= Counter then return pet else end end
end
endfunction detectIndex(player, petName)
local folder = player:WaitForChild(“Pets Index”)if folder:FindFirstChild(petName) then
if folder:FindFirstChild(petName).Value == false then
folder:FindFirstChild(petName).Value = true
end
end
endfunction hatchOne(Player, eggName)
local chosenPet = choosePet(Player, eggName)
local val = Instance.new(“StringValue”)
val.Name = chosenPet[1]
val.Parent = Player:WaitForChild(“Pets”)detectIndex(Player, chosenPet[1])
EggRemoteEvents:WaitForChild(“hatchOne”):FireClient(Player, eggName, chosenPet[1])local pets = {}
for i, v in pairs(Player.Pets:GetChildren()) do
table.insert(pets, v.Name)
end
dataStore:SetAsync(Player.UserId…“Pets”, pets)
EggRemoteEvents:WaitForChild(“addPetList”):FireClient(Player, chosenPet[1])
return chosenPet
endgame:GetService(“Players”).PlayerAdded:Connect(function(player)
marketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId)
if userId == player.UserId then
if productId == 1623953870 then
hatchOne(game:GetService(“Players”):GetPlayerByUserId(userId), “Basic Egg”)
return Enum.ProductPurchaseDecision.PurchaseGranted
endend
end)
end)