My developer product works perfectly fine in Roblox Studio, but in an actual instance of Roblox, it ceases to function. I have no idea why this is, as it does not product any errors in console. Keep in mind that both clients are completely unmodified.
I think it is due to debounce, because when I removed it, it functioned correctly. Only issue is that it did the function 10-15 times.
Message to prompt (if this helps):
local function onTouchTap() -- buy
script.Parent:TweenSize(sizesmall,"Out","Quad",0.05)
MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, ProductID)
wait(.05)
script.Parent:TweenSize(default,"Out","Quad",0.05)
end
Function when bought:
local ProductID = 3155119978 -- Change this ID to your DeveloperProduct ID.
local MarketplaceService = game:GetService("MarketplaceService")
local debounce = true
local function handlePurchase(info)
local ReceivedProductID = info.ProductId
local Player = game.Players:GetPlayerByUserId(info.PlayerId)
if ReceivedProductID == ProductID then
if Player then
if debounce then
debounce = false
print(Player.Name .. " Purchased 1 Redshift's 10,000 Subscriber Award")
local clone = script.ParticleEmitter:Clone()
local clone2 = script.PointLight:Clone()
clone.Parent = workspace[Player.Name].HumanoidRootPart
clone2.Parent = workspace[Player.Name].HumanoidRootPart
game.ReplicatedStorage.RemoteEvent:FireAllClients(Player)
game.ReplicatedStorage.Thankyou:FireClient(Player)
game.ReplicatedStorage.Thankyou2:FireAllClients(Player)
game.ReplicatedStorage.Trophy:Clone().Parent = Player.Backpack
debounce = true
wait(10)
clone.Rate = 0
end
end
end
end
MarketplaceService.ProcessReceipt = handlePurchase
Oh and btw: there can be something with the way youโre checking gor user buying the devproduct. Iโd put the remoteEvent to assign the other part of the code.
Do not use workspace[player.Name] to reference a playerโs character. Player instances have a โCharacterโ property which holds a reference to their character model in Workspace. You do not need a debounce either. MarketplaceService.ProcessReceipt does not execute more than once per transaction
debounce is a global variable. If multiple players purchase at the same time, it causes an error.
implement a player debounce using a table.
you also set debounce = true before the wait(10) call. other purchases could be triggered during the waiting period.
local playerDebounce= {}
if not playerDebounce[player.UserId] then
playerDebounce[player.UserId] = true
--
--
--
task.wait(10)
playerDebounce[player.UserId] = nil -- reset debounce after delay
end