Greetings, I have a script that prints "Player has purchased the asset" and fires a RemoteEvent once a player buys a clothing asset, however if the player clicks multiple times on the ClickDetector that opens the Purchase Prompt or cancels and opens the Purchase Prompt multiple times before purchasing the asset then it causes "Player has purchased the asset" and the RemoteEvent to be fired multiple times.
Thanks in advance!
script.Parent.MouseClick:connect(function(player)
local ID = script.Parent.Parent.ID.Value
local MarketPlaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("PurchaseMessage")
local AssetType = "shirt"
if MarketPlaceService:PlayerOwnsAsset(player, ID) == false then
MarketPlaceService:PromptPurchase(player, ID)
MarketPlaceService.PromptPurchaseFinished:connect(function(player, ID, IsPurchased)
if IsPurchased then
print("Player has purchased the asset")
local playername = player.DisplayName
RemoteEvent:FireAllClients(playername, AssetType)
end
end)
else
local GUI = ServerStorage.OwnsClothingAsset:Clone()
GUI.Parent = player.PlayerGui
wait(1.5)
GUI:Destroy()
end
end)

2 comments
Is it a Developer Product or a Gamepass or a Shirt?
It's a shirt