Im sure that works, but for me when I try to purchase it, it brings my coins back down to 0 instead of it going up… here is my leaderstat code
-- variables --
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
local MPS = game:GetService("MarketplaceService")
-- leaderstats --
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = Leaderstats
local Strength = Instance.new("IntValue")
Strength.Name = "Strength"
Strength.Parent = Leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Water"
Rebirths.Parent = Leaderstats
local CoinsData
local StrengthData
local RebirthsData
local Success, ErrorMessage = pcall(function()
CoinsData = DataStore:GetAsync(Player.UserId.."-CashData")
StrengthData = DataStore:GetAsync(Player.UserId.."-PointsData")
RebirthsData = DataStore:GetAsync(Player.UserId.."-RebirthsData")
end)
if not Success then
print(ErrorMessage)
end
if CoinsData ~= nil then
Coins.Value = CoinsData
else
Coins.Value = 0
end
if StrengthData ~= nil then
Strength.Value = StrengthData
else
Strength.Value = 0
end
if RebirthsData ~= nil then
Strength.Value = RebirthsData
else
Strength.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
pcall(function()
DataStore:SetAsync(Player.UserId.."-CashData", Player.leaderstats.Coins.Value)
DataStore:SetAsync(Player.UserId.."-PointsData", Player.leaderstats.Strength.Value)
DataStore:SetAsync(Player.UserId.."-RebirthsData", Player.leaderstats.Rebirths.Value)
end)
end)
-- Purchase --
local coinsProductIDs =
{
[1150214074] = (30 * (10^60)),
[1096715119] = 500,
[1096715447] = 1000,
[1096715703] = 5000,
}
MPS.ProcessReceipt = function(purchaseInfo)
local plrPurchased = game.Players:GetPlayerByUserId(purchaseInfo.PlayerId)
if not plrPurchased then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
for productID, coinsGiven in pairs(coinsProductIDs) do
if purchaseInfo.ProductId == productID then
plrPurchased.leaderstats.Coins.Value = plrPurchased.leaderstats.Coins.Value + coinsGiven
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
Here is also the display script for the text label but I don’t think that would affect the leaderstats
local abbrev = {"","K","M","B", "t", "q", "Q", "s", "S", "o", "n", "d", "U", "D", "T", "Qt", "Qd", "Sd", "St", "O", "N", "v", "c"}
local function Format(value, idp)
local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
local abbrevs = abbrev[1 + ex] or ("e+"..ex)
local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)
return ("%."..idp.."f%s"):format(normal, abbrevs)
end
while wait() do
local player = game.Players.LocalPlayer
script.Parent.Text = Format(player.leaderstats.Coins.Value,2)
end```