hello. im trying to make a product purchase item giver but for some reason i dont get the item after i bought it please help!
script.Parent.Transparency = 1
script.ITEM.Value.Handle.CanTouch = false
script.ITEM.Value.Handle.CanQuery = false
script.ITEM_WELD.Value.Part1 = script.ITEM.Value:FindFirstChild("Handle")
script.ITEM_WELD.Value.Enabled = true
local ASSET_ID = 1558906921
local db = true
function blah(player)
--if not player.Backpack:FindFirstChild(""..script.ITEM.Value.Name.."") and not player.Character:FindFirstChild(""..script.ITEM.Value.Name.."") then
if db == true then db = false
local player = game.Players:FindFirstChild(player.Name) -- Finds the player
local ITEM = script.ITEM.Value:Clone()
ITEM.Handle.CanTouch = true
ITEM.Parent = player.Backpack
if script.INFINITE.Value == true then
db = true
else
script.Parent.Parent:Destroy()
end
db = true
end
db = true
end
function Buy(plr)
game.MarketplaceService:PromptProductPurchase(plr, ASSET_ID)
end
function processReceipt(ReceiptInfo)
-- Find the player who made the purchase in the server
local productId = ReceiptInfo.ProductId
local player = game.Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if not player then
warn("no player")
end
warn("purchase accepted")
if productId == ASSET_ID then
warn(player.Name.." bought "..productId)
blah(player)
end
end
game.MarketplaceService.ProcessReceipt = processReceipt
script.PROMPT.Value.Triggered:Connect(Buy)
Hi. To be honest I can’t with confidence say what’s wrong here. So this is just tips I think
Use game:GetService() instead of game.Service because service may not exist
When you trying to use ProcessReceipt return as result Enum.ProductPurchaseDecision.PurchaseGranted if purchase is processed properly and Enum.ProductPurchaseDecision.NotProcessedYet if something goes wrong(player left, data store errors etc). It is very important because if you return NotProcessedYet Roblox will try again later
Correct me if I’m wrong, but when you destroy script(script.Parent.Parent:Destroy() in blah function) bonded function destroys too? Plus I can’t figure why you use db
Sorry for late reply.
Here is code that I tried to fix, but I dont guarantee that code will work properly(I didn’t tested this code properly). I don’t understand what you trying to do
local ASSET_ID = 1558906921
local MarketplaceService = game:GetService("MarketplaceService") -- Use instead of game.MarketplaceService
script.Parent.Transparency = 1
script.ITEM.Value.Handle.CanTouch = false
script.ITEM.Value.Handle.CanQuery = false
script.ITEM_WELD.Value.Part1 = script.ITEM.Value:FindFirstChild("Handle")
script.ITEM_WELD.Value.Enabled = true
function blah(player)
local player = game.Players:FindFirstChild(player.Name)
local ITEM = script.ITEM.Value:Clone()
ITEM.Handle.CanTouch = true
ITEM.Parent = player.Backpack
if not script.INFINITE.Value then
-- I can't understand what you trying to do here
-- but you must keep Script alive(do not destroy)
-- because if you do this your function processReceipt will destroy too!
-- script.Parent.Parent:Destroy()
end
end
function Buy(plr)
MarketplaceService:PromptProductPurchase(plr, ASSET_ID)
end
function processReceipt(ReceiptInfo)
local productId = ReceiptInfo.ProductId
local player = game.Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if not player then
warn("no player")
return Enum.ProductPurchaseDecision.NotProcessedYet -- stop execution. Roblox will try again later
end
warn("purchase accepted")
if productId == ASSET_ID then
warn(player.Name.." bought "..productId)
blah(player)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- well, we are at end but product didnt found
return Enum.ProductPurchaseDecision.NotProcessedYet
end
MarketplaceService.ProcessReceipt = processReceipt
script.PROMPT.Value.Triggered:Connect(Buy)
If you use db in this case you must return for example true/false that indicates your code executed or not. Because if execution will skip due db, function will do nothing and processReceipt will return PurchaseGranted
In addition I think db is not required in this code because there is nothing what can yield execution or mix it up. So, I removed db