I'm making a gamepass GUI shop for my game and I cannot find the error, however when I try to buy a gamepass I get this text:
"Your purchase failed because something went wrong. Your account has not been charged. Please try again later."
Here is my PurchaseScript
local MarketplaceService = game:GetService("MarketplaceService")
--[TOOLS]
local tools = game.ServerStorage.Tools
--[id] = ToolName
local list = {
[21842414] = "GravityCoil",,
[21842376] = "SpeedCoil",
[90075532] = "SuperCoil",
}
local skip = 1179259924
local function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game
-- If they come back, the callback will be called again
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
local sound = Instance.new("Sound", player)
sound.SoundId = "rbxassetid://254003734"
sound.PlayOnRemove = true
sound:Play()
sound:Destroy()
if receiptInfo.ProductId == skip then --SKIP STAGE
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
player:LoadCharacter()
else
local tool = list[receiptInfo.ProductId] --TOOL
tools:FindFirstChild(tool):Clone().Parent = player.Backpack
tools:FindFirstChild(tool):Clone().Parent = player.StarterGear
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
I think though the bug may be coming from my LocalScript? I have an ImageButton opening prompts yet however it's not working.
local player = game.Players.LocalPlayer
local ScreenGui = script.Parent
local ShopButton = ScreenGui:WaitForChild("ShopButton")
local ShopFrame = ScreenGui:WaitForChild("ShopFrame")
local SkipStageButton = ScreenGui:WaitForChild("SkipStageButton")
local UserInputService = game:GetService("UserInputService")
local MarketplaceService = game:GetService("MarketplaceService")
function promptProduct(productID)
MarketplaceService:PromptProductPurchase(player, productID)
end
local DB = false
ShopButton.MouseButton1Down:Connect(function()
if not DB then
DB = true
if ShopFrame.Visible then
ShopFrame.Visible = false
else
ShopFrame.Visible = true
end
wait(0.5)
DB = false
end
end)
SkipStageButton.MouseButton1Down:Connect(function()
promptProduct(1179259924)
end)
--[SHOP FRAME]
for i,v in pairs(ShopFrame:GetDescendants()) do
if v:IsA("ImageButton") then
v.MouseButton1Down:Connect(function()
promptProduct(tonumber(v.Name))
end)
end
end
--[HOVER SOUND EFFECT]
for i,v in pairs(ScreenGui:GetDescendants()) do
if v:IsA("ImageButton") then
v.MouseEnter:Connect(function()
local sound = Instance.new("Sound", player)
sound.SoundId = "rbxassetid://408524543"
sound.PlayOnRemove = true
sound:Play()
sound:Destroy()
end)
end
end
--[REPOSITION FOR MOBILE]
if UserInputService.TouchEnabled then
wait()
ShopButton.Position = UDim2.new(0, 0,0.45, 0)
SkipStageButton.Position = UDim2.new(0, 0,0.45, 0)
end
