When purchasing developer product, Every product is purchased

  1. What do you want to achieve?
    There are 5 developer products, 4 provide coins and 1 provides a sword tool.When you purchase a developer product, the players coin leaderstat is increased accordingly (or) the player is given a sword

  2. What is the issue?
    Once the player purchases any product, all products activate at once. The player is given a sword and the sum of all coins

  3. What solutions have you tried so far?
    I redefined marketplace service after each function but i didn’t notice a difference.

events are fired via a textbutton gui

local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	local timealive = player.leaderstats:FindFirstChild("Coins")
	if purchased then
		timealive.Value = timealive.Value +250
	end
end)

game.ReplicatedStorage:WaitForChild("Buy1Coin").OnServerEvent:Connect(function(player)
	mkp:PromptProductPurchase(player,1195449239)
end)
-- first above
local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	if purchased then
		game.ReplicatedStorage.Sword:Clone().Parent=player.Backpack
	end
end)

game.ReplicatedStorage:WaitForChild("Swordbuy").OnServerEvent:Connect(function(player)
	mkp:PromptProductPurchase(player,1195450585)
end)
-- sword purchase above
local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	local timealive = player.leaderstats:FindFirstChild("Coins")
	if purchased then
		timealive.Value = timealive.Value +600
	end
end)

game.ReplicatedStorage:WaitForChild("Buy2Coin").OnServerEvent:Connect(function(player)
	mkp:PromptProductPurchase(player,1195449240)
end)
-- second purchase
local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	local timealive = player.leaderstats:FindFirstChild("Coins")
	if purchased then
		timealive.Value = timealive.Value +1250
	end
end)

game.ReplicatedStorage:WaitForChild("Buy3Coin").OnServerEvent:Connect(function(player)
	mkp:PromptProductPurchase(player,1195449242)
end)
-- third purchase above



-- fourth
local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	local timealive = player.leaderstats:FindFirstChild("Coins")
	if purchased then
		timealive.Value = timealive.Value +3250
	end
end)

game.ReplicatedStorage:WaitForChild("Buy4Coin").OnServerEvent:Connect(function(player)
	mkp:PromptProductPurchase(player,1195449241)
end)
-- fourth

Your not checking to see if the purchase made was the one for that code to run instead it runs anyway on everything

Nor are you checking the player

Each function is connected to an event??
“game.ReplicatedStorage:WaitForChild(“Swordbuy”).OnServerEvent:Connect(function(player)”
and the player is found, they sent the event from a textbutton
local player = game.Players:GetPlayerByUserId(userId)

Is this is the server or on the guide or something? If so I stand corrected and are they multpul scripts?

You only need one MarketplaceService | Roblox Creator Documentation set up, then check the id’s inside.

“Every product is purchased” because you have listeners for every product (with your logic).

1 Like

Unless you have multipul scripts

There is absolutely no need for more than 1 listener for this.
Having multiple will break it if you aren’t checking the id’s (don’t).

Having more than 1 is not recommended either.

Yes and also you need to do this:

If product == swordId then
Give sword code here
End

I understand now, Thanks. How would i check the Id of a product?
if product == 0000?

Yes but with the correct Id of course

1 Like

MarketplaceService | Roblox Creator Documentation has 3 parameters.

  1. UserId (int64)
  2. ProductId (int64) - which you’ll be using to check
  3. IsPurchased (bool) - either true or false
1 Like

ex;

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
	local player = game.Players:GetPlayerByUserId(userId)
	local timealive = player.leaderstats:FindFirstChild("Coins")
	if purchased and product == 000000 then --// replace the 000000 with your product id
		timealive.Value = timealive.Value +250
	end
end)
1 Like