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
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”).
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
local marketplaceservice = game:GetService("MarketplaceService")
local id100 = 1762467891
local id250 = 1762468506
local id500 = 1762468954
local id1000 = 1762470712
marketplaceservice.ProcessReceipt = function(receiptInfo)