MarketPlaceService Problem?

So, I Have two problems the first one is that when the player buys the developer product the event fires 2,3 or 4 times for some reason. The second problem is that after the part “PromptProductPurchaseFinished”, the player variable turns into the userId, but I need the player.

Could someone help me?

local MarketplaceService = game:GetService("MarketplaceService")
local serverScriptService = game:GetService("ServerScriptService")
local inLine = script.Parent:WaitForChild("InLine")
local clickDetector = script.Parent
local gamepassID = 1893240069
local waitTime = serverScriptService.BallScript.WaitTime

local players = {}

wait(waitTime.Value + 1)

clickDetector.MouseClick:connect(function(player)
	
	MarketplaceService:PromptProductPurchase(player, gamepassID)
	
	MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, gamepassID, purchased)
		if purchased then
			if not player[player.Name] then -- I know I could use table.find, but that dind't work because of the userId
				table.insert(players,player.Name)
				inLine.Value += 1
			else
				wait(1)
				table.remove(players,player.Name)
			end
		end
	end)
end)

You can use player service to get the player from the userId with

players:GetPlayerFromUserId(ID)

I’m not sure that’s the exact name of the function but I’m sure if you start typing it in it’ll pop up

NEVER, and I mean NEVER use the PromptProductPurchaseFinished event. I have read multiple times that it is super unsafe and vulnerable to exploits- basically, people can trick it super easily into thinking they purchased the product when actually, they didn’t.

My recommendation is to always use ProcessReceipt (read up on it there.) Unlike PromptProductPurchaseFinished, not only does it prevent that “exploit,” but it also handles cases where if the player disconnects or leaves before getting their reward, it will give it to them next time they join. There’s a whole lot more benefits to using it, but that’s just a few.

Also, it only runs once :wink:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.