DevProduct is buying everything

So i have 4 devproducts that give you points when you buy them
The thing is though, whenever i buy one it gives me all the other devproduct’s points too

I have a +100, 250, 500 and 1000 points devproduct and when i buy one it gives me all of those combined (1850)

This is my script

local marketplaceservice = game:GetService("MarketplaceService")
local id = 1762467891 --- this is for the 100 one, and i put different ids on other ones

game.Players.PlayerAdded:Connect(function(player)
	local userid = game.Players:GetUserIdFromNameAsync(player.Name)
marketplaceservice.PromptProductPurchaseFinished:Connect(function(userid, id, ispurchased)
	if ispurchased == true then
		player.leaderstats.Points.Value += 100
		print(player.Name .. " bought the devproduct")
	else
		print(player.Name .. " didnt buy the devproduct")
		end
	end)
end)

buy script

local player = game.Players.LocalPlayer
local marketplaceservice = game:GetService("MarketplaceService")
local id = 1762467891

script.Parent.MouseButton1Click:Connect(function()
marketplaceservice:PromptProductPurchase(player, id)
end)

my devproduct prompters are local scripts in a gui, the handlers are in serverscriptservice

You need to check if the ID of the product matches the correct one before adding points. I would recommend using MarketplaceService.ProcessReceipt instead, and make it seperate from PlayerAdded:

marketplaceservice.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	player.leaderstats.Points.Value += 100
	print(player.Name .. " bought the devproduct")
end)

Note that you can only have ProcessReceipt once, so merge all of the other devproduct scripts into this one. (btw get the productId from receiptInfo.ProductId

is it meant to be like this?

game.Players.PlayerAdded:Connect(function(player)
	
	marketplaceservice.ProcessReceipt = function(receiptInfo)	
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
		local id = receiptInfo.ProductId
        marketplaceservice.PromptProductPurchaseFinished:Connect(function(userid, id, ispurchased)
	
	    if ispurchased == true and id == id100 then
		    player.leaderstats.Points.Value += 100
		    print(player.Name .. " bought the 100 devproduct")
	    else
		    print(player.Name .. " didnt buy the 100 devproduct")
		end
		
			if ispurchased == true and id == id250 then
				player.leaderstats.Points.Value += 250
				print(player.Name .. " bought the 250 devproduct")
			else
				print(player.Name .. " didnt buy the 250 devproduct")
			end
			
			if ispurchased == true and id == id500 then
				player.leaderstats.Points.Value += 500
				print(player.Name .. " bought the 500 devproduct")
			else
				print(player.Name .. " didnt buy the 500 devproduct")
			end
			
			if ispurchased == true and id == id1000 then
				player.leaderstats.Points.Value += 1000
				print(player.Name .. " bought the 1000 devproduct")
			else
				print(player.Name .. " didnt buy the 1000 devproduct")
			end
			
	end)
	end
end)

That’s not how you should do it. I’d recommend using the model in the Documentation, you can find it here if you scroll down a bit (under “Handling Purchases”).

It should be like this (don’t added PlayerAdded):

marketplaceservice.ProcessReceipt = function(receiptInfo)	
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local id = receiptInfo.ProductId
	
	if id == id100 then
		player.leaderstats.Points.Value += 100
		print(player.Name .. " bought the 100 devproduct")
	elseif id == id250 then
		player.leaderstats.Points.Value += 250
		print(player.Name .. " bought the 250 devproduct")
	elseif id == id500 then
		player.leaderstats.Points.Value += 500
		print(player.Name .. " bought the 500 devproduct")
	elseif id == id1000 then
		player.leaderstats.Points.Value += 1000
		print(player.Name .. " bought the 1000 devproduct")
	end
end

how do i get the player then because it says “attempt to index number with “leaderstats””

What do you mean? player is the player. It’s probably coming from another part of the script.

oh wait my bad

i thought in this part

marketplaceservice.PromptProductPurchaseFinished:Connect(function(player, id, ispurchased)

you had to make the first parameter the player from a variable

Oh
I’m still confused, has it worked yet? If it did mark the post as the solution, thanks.

Yes it does work
The thing is though now
Whenever i buy it twice it doubles the amount of points i get
i even added

	return Enum.ProductPurchaseDecision.PurchaseGranted

on it, but when i test it, it still doubles
should i make a new post about this issue

Have you put ProcessReceipt outside and not in any connections (like PlayerAdded, PromptPurchase, etc)? It needs to be like that.

local marketplaceservice = game:GetService("MarketplaceService")
local id100 = 1762467891
local id250 = 1762468506
local id500 = 1762468954
local id1000 = 1762470712

marketplaceservice.ProcessReceipt = function(receiptInfo)

its on line 7 right under all the ids

Have you deleted the other scripts that handles the ids yet? Check if any marketplace scripts exist.

i deleted the other devproduct scripts, the only other scripts i have that use marketplaceservice scripts are gamepass scripts

found the fix to the double devproduct problem by looking into ProcessReceipt