Hi, I made a store in the game where you can use a proximity prompt to trigger a purchase. The code is suppose to go through all the items and check if you own it using the Marketplace Service API. For some reason it doesn’t always return a result.
Here is the code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Equip = Remotes:WaitForChild("Equip")
local WeaponsFolder = workspace:WaitForChild("DisplayWeapons")
local function HasGamepass(GamepassId)
local Success,Results = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(Players.LocalPlayer.UserId, GamepassId)
end)
if Success and Results then
return true
end
end
for Index, Weapon in ipairs(WeaponsFolder:GetChildren()) do
local Prompt: ProximityPrompt = Weapon:FindFirstChild("ProximityPrompt")
local Id: IntValue = Weapon:FindFirstChild("GamepassId").Value
if HasGamepass(Id) then
Prompt.ActionText = "Equip"
else
Prompt.ActionText = "Buy"
end
Prompt.Triggered:Connect(function() PromptGamepassPurchase(Id) end)
end
I’m pretty sure this is because I’m calling the API too much. Not quite sure, need some help with this!
You should use warn if a pcall fails. There’s a good starting point for eyeing this down.
local Success,Results = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(Players.LocalPlayer.UserId, GamepassId)
end)
if not Success then
warn(`Failed to check gamepass {GamepassId}: {Results}`)
return false
end
Are you sure you’re getting a pcall response of true, nothing?
Thats, not how that UserOwnsGamePassAsync should work, it should always return. If it doesn’t, its almost definitely an error, which is why I said you should output the result of the pcall for debugging sake.
I tried printing the result of UserOwnsGamePassAsync, it only sometimes work. I have another script using it as well, and it works fine. So I don’t know if I am calling it too much