Just figured out what I’m saying is actually completely wrong, it’s to do with the remote event being fired, it’s not being fired twice, but whats in it (promptgamepasspurchasefinished) is firing multiple times in the way I described. If I click the button twice it fires the event twice, I don’t understand at all how this can happen because the event is only being fired once. I have a disconnection already on this event, I guess it isn’t working.
local gamePassPurchaseConnection
--other code--
gamePassPurchaseConnection = game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,passId,purchased)
if purchased then
gamePassPurchaseConnection:Disconnect()
--other code--
14:46:01.774 fired - Client - buttonClicked:5 (clicked once, didnt press anything on the prompt, just kept it there)
14:46:05.690 fired - Client - buttonClicked:5 (clicked again with the prompt open but this time i bought the gamepass)
14:46:09.023 Recieved the event -- As you can see by these lines it receives the event twice
14:46:09.023 fired - Server
14:46:09.023 Recieved the event - Server
14:46:09.023 fired - Server
14:46:09.072 ▶ recieved (x2) - Server
Sorry, again, after more debugging it seems that the remote event is being fired everytime the player clcicks button but is actually only ever getting recieved when the player purchases the pass
Simply move the PromptGamePassPurchaseFinished connection outside of the button clicked event, so that it only connects once. This should solve your issue.
Actually, the passid is stored in an intvalue, I could loop through the children of the thing that all the values are in and put the purchasefinished in there?
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr, gamePassId, wasPurchased)
if gamePassId == desiredID then
-- desiredID was purchased
end
end)
Thats how you check the gamepass ID. Change desiredID to whatever ID you desire.
And now just move the function outside of the clicked event, so that it only connects once.
for i,v in pairs(workspace.djBooths:GetChildren()) do
if v:FindFirstChild("itemsPart") then
for e,f in pairs(v.itemsPart.itemsPartGui.holderFrame.itemsFrame:GetChildren()) do
if f:IsA("TextButton") then
local id = f.itemId.Value
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr, id, wasPurchased)
print("finished")
end)
end
end
end
end
Nothing is printing, I’m suspecting it’s because the children change after the script is created?
Apologies, thought that was what you ment but I didn’t actually know that was possible, I believe it works good now, I have a lot more code to change so it fits with this new code, I will get back to you, thank you.