local TextButton = script.Parent
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local destination = game.Workspace.dest.Position
local productId = 1815441724
local function teleportPlayer()
character:PivotTo(CFrame.new(destination))
print("Teleported player")
end
local function handlePurchaseFinished(productId, wasPurchased)
print("Purchase finished event fired")
if wasPurchased then
teleportPlayer()
print("Product purchased, so teleported")
else
print("Product not purchased, did not teleport player")
end
end
local function onClick()
MarketplaceService:PromptProductPurchase(player, productId)
print("Prompted purchase for product with ID:", productId)
end
MarketplaceService.PromptProductPurchaseFinished:Connect(function(productId, wasPurchased)
handlePurchaseFinished(productId, wasPurchased)
end)
TextButton.Activated:Connect(onClick)
I’m having an issue where purchase checks are not working properly. I think my logic here may be wrong. If the user cancels the purchase prompt, it’s counted as a successful purchase so the player teleports which is not what I want, the player should not teleport. The condition where they purchase the product works fine though. So, what I’m trying to say is, cancelling and purchasing results in teleports (successful purchase case).
Also if I say if was purchased == true
then in both situations, it’s counted as an unsuccessful purchase, so teleportation does not occur.
I’m not a programmer, I made it using AI.