I have a system where it is supposed to fire a Client event when it’s purchased. For some reason, not purchasing the Mini Storm before any other ones completely breaks it and doesn’t spawn it due to a “Transform function error”. None of the code for any of it is any different except for the product ids.
This is the code I have so far:
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local minievent = ReplicatedStorage:FindFirstChild("Mini")
local stormevent = ReplicatedStorage:FindFirstChild("Storm")
local omegaevent = ReplicatedStorage:FindFirstChild("Omega")
-- Data store for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- ProductId 123123 for a full heal
-- ProductId 456456 for 100 gold
productFunctions[1298117676] = function(receipt, player)
omegaevent:FireClient(player)
return true
end
productFunctions[1298116021] = function(receipt, player)
minievent:FireClient(player)
return true
end
productFunctions[1274234003] = function(receipt, player)
stormevent:FireClient(player)
return true
end
productFunctions[1274234002] = function(receipt, player)
player.leaderstats.Credits.Value += 100
return true
end
productFunctions[1274234005] = function(receipt, player)
player.leaderstats.Credits.Value += 250
return true
end
productFunctions[1274234001] = function(receipt, player)
player.leaderstats.Credits.Value += 1000
return true
end
productFunctions[1274234004] = function(receipt, player)
player.leaderstats.Credits.Value += 2500
return true
end
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
-- Determine if the product was already granted by checking the data store
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local success, isPurchaseRecorded = pcall(function()
return purchaseHistoryStore:UpdateAsync(playerProductKey, function(alreadyPurchased)
if alreadyPurchased then
return true
end
-- Find the player who made the purchase in the server
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
script.Parent.Buyer.Value = player.Name
if not player then
-- The player probably left the game
-- If they come back, the callback will be called again
return nil
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
-- If granting the product failed, do NOT record the purchase in datastores.
if not success or not result then
error("Failed to process a product purchase for ProductId:", receiptInfo.ProductId, " Player:", player)
return nil
end
-- Record the transcation in purchaseHistoryStore.
return true
end)
end)
if not success then
error("Failed to process receipt due to data store error.")
return Enum.ProductPurchaseDecision.NotProcessedYet
elseif isPurchaseRecorded == nil then
-- Didn't update the value in data store.
return Enum.ProductPurchaseDecision.NotProcessedYet
else
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
I don’t know why it only does it if I don’t buy the Mini storm first, and that it goes through for all the other ones if I buy the Mini storm first.