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

Need Help With Weird Bug Inside of In Game Currency Buttons?

Asked by 6 years ago

Ok so I am having a problem with my button script. It seems as though no matter what button I push it only defaults to 12,000 in in game currency. So the buttons are as follows:

12,000 1500 3000 50000 6000 750

So If I push 750 it still defaults to 12,000, if I push 3000 it also defaults to 12,000.

BUT the crazy thing is that the developer product that shows up is the right one. So If I push 1500 it will show that I pushed 1500 but it will still give me 12000 of in game currency after I purchase 1500

Here is the code:

Server Script

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)
end)

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


SaveToDataStore:FireServer(money.Value)

end
end
    end
    end

LocalScript

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"

button.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)
    end
end
0
Did you make sure numvalue is correct for each button? DeveloperSolo 370 — 6y

Answer this question