Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Developer Products Keep Charging More With Every Purchase?

Asked by 7 years ago
Edited 7 years ago

OK So I a having trouble with a script. My problem is that that I have a script that handles Developer Tool Purchases. The first time someone purchases something it works fine, BUT if someone tries to purchase something ore than once it gives them the item 2 TIMES and charges them twice even though it should only charge them once. I know this ay sound confusing but I will try to clarify it.

If they buy $100 of in game currency the first time. Its gives the $100. If they try to buy it again it will give them $200 and charge them double the robux. If they try too purchase it 3 times it will give them $300 and triple the robux.

So The first time it gives them: $100 and charges them R$50, the second time it gives them $200 + the $100 from the original purchase and charges them R$100 plus the original R$50 they spent for the first purchase.

I cannot understand why it wouldn't just charge them for each purchase made and why it keeps progressing every time they push the button to purchase an item. Here is the script, please let me know if I did something wrong and also if there is a better way of going about this.

Here is the code for it:

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
money.Value = money.Value + NumValue

print ("Second Time It Processes" .. NumValue)

SaveToDataStore:FireServer(money.Value)
return
end
end
end)
    end

end

1 answer

Log in to vote
1
Answered by 7 years ago

Well I figure it out and I am just keeping this up to let anyone else know who happens to run into this problem. I forgot to put

    return Enum.ProductPurchaseDecision.PurchaseGranted     

at the end of the script. Wow I feel dumb LOL

0
LOL Aimarekin 345 — 7y
0
Lol trust me, returns are typically the thing everyone forgets. I had troubles with my datastore library for the longest time. Then I remembered to put return.... Tomstah 401 — 7y
0
LMAO. Yeah I figured out a way around 1 problem and now ran into another trying to call RemoteEvents with Buttons In Pairs.Cannot figure it out for the life of me CrazyRoblots 13 — 7y
Ad

Answer this question