There is money on the leaderboard. I made it possible to buy money with Lobos
If you buy it for the first time, you can buy it normally, but if you buy it for the second time, you can buy it twice. How can I fix it
example=>100 +100 =200 (I want to make it like this)
Actual error =>100 +100 = 300
local market = game:GetService("MarketplaceService")
market.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local plr = game.Players:GetPlayerByUserId(userid)
local leaderboard = plr.leaderstats
local coins = leaderboard.Money
if productid == 1506484176 then
coins.Value += 100
elseif productid == 1507002962 then
coins.Value += 300
elseif productid == 1507003592 then
coins.Value += 700
elseif productid == 1507004130 then
coins.Value += 1000
end
end
local market = game:GetService("MarketplaceService")
market.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local plr = game.Players:GetPlayerByUserId(userid)
local leaderboard = plr.leaderstats
local coins = leaderboard.Money
if productid == 1506484176 then
coins.Value += 100
end
if productid == 1507002962 then
coins.Value += 300
end
if productid == 1507003592 then
coins.Value += 700
end
if productid == 1507004130 then
coins.Value += 1000
end
end
I think I encountered the same problem. I removed all the elseif and it worked for some reason.
Save last value from BEFORE purchased, then check the value after, if its different bigger than the placeholder then its supposed to be take it away. Idk this is my solution, not sure if it will work. Example:
if productid == [ID] then
local oldCash = coins.Value
wait(1)
coins.Value += [placeholder]
if oldCash == coins.Value + 300 then
coins.Value = coins.Value - 100
end
end
I researched a bit. Basically what happens is Roblox wants to know if purchase is successful. Until it is told, this callback will be running many times. Therefore, it runs two times because it thinks that the purchase isn’t successful. But when it becomes successful, it already runs two times. Here’s some links to reference. ProcessReceipt and ProductPurchaseDecision .
local function processReceipt(receipt)
--do stuff
return Enum.ProductPurchaseDecision.PurchaseGranted
end
marketPlaceService.ProcessReceipt:Connect(processReceipt)
For your code, this would be -
local market = game:GetService("MarketplaceService")
market.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local plr = game.Players:GetPlayerByUserId(userid)
local leaderboard = plr.leaderstats
local coins = leaderboard.Money
if productid == 1506484176 then
coins.Value += 100
elseif productid == 1507002962 then
coins.Value += 300
elseif productid == 1507003592 then
coins.Value += 700
elseif productid == 1507004130 then
coins.Value += 1000
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end