Hello,
Can someone please help me with this code. y problem is that after I push the buy button the first time it ADDS a product to the product purchased.
THIS IS WHAT IS HAPPENING. If I buy a developer product E.G. a gun then the fist time it will give me 1 gun but the second time it gives me 2 guns instead of one and the third time it will give me 3 guns etc etc etc. Like So.
First time = Gun second time = Gun Gun third time = Gun Gun Gun
THE BIG PROBLEM IS THAT IT ALSO CHARGES 2 TIMES AFTER THE FIRST PURCHASE AND 3 TIMES ETC... ETC.. ETC.. AFTER THE CONCURRENT PURCHASES.
I really need this script fixed but no matter what I do its not working. If someone could help me I would be very grateful for the help. Thank you
local SaveToDataStore = game.ReplicatedStorage.SaveToDataStore
local player = script.Parent.Parent.Parent.Parent
local money = player.leaderstats.Money
print(script.Parent.Parent.Parent.Parent)
function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end
for _, button in pairs(script.Parent:GetChildren()) do
if button:IsA("TextButton") then
local productId = button.Value.Value
local mps = game:GetService"MarketplaceService"
local NumValue = button.NumValue.Value
button.MouseButton1Click:connect(function()
mps:PromptProductPurchase(script.Parent.Parent.Parent.Parent, productId)
mps.ProcessReceipt = function(info)
local plr = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild"leaderstats" and plr.leaderstats:FindFirstChild"Money" then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + NumValue
print ("Second Time It Processes" .. NumValue)
SaveToDataStore:FireServer(money.Value)
return
end
end
end)
end
end
