Whenever i give myself cash it's suppose to save but it won't
`local currencyName = "Cash" local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = player local currency = Instance.new("IntValue") currency.Name = currencyName currency.Parent = folder local ID = currencyName.."-"..player.UserId local savedData = nil pcall(function() local savedData = DataStore:GetAsync(ID) end) if savedData ~= nil then currency.Value = savedData print("Data loaded") else currency.Value = 100 print("Players to the game") end end) game.Players.PlayerRemoving:Connect(function(player) local ID = currencyName.."-"..player.UserId DataStore:SetAsync(ID,player.leaderstats[currencyName].Value) end) game:BindToClose(function() for i,player in pairs(game.Players:GetPlayers()) do if player then player:Kick("This game is shutting down ok.") end end wait(5) end)`
Try using these two scripts:
local MPS = game:GetService("MarketplaceService") MPS.ProcessReceipt = function(receiptInfo) if receiptInfo.ProductId == 438167434 then -- replace with your ID here local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1000 return Enum.ProductPurchaseDecision.PurchaseGranted elseif receiptInfo.ProductId == 443462976 then -- replace with your ID here local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5000 return Enum.ProductPurchaseDecision.PurchaseGranted elseif receiptInfo.ProductId ==443463248 then -- replace with your ID here local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10000 return Enum.ProductPurchaseDecision.PurchaseGranted end end
This is just an example you can change the amount of money and money name
game.Players.PlayerAdded:connect(function(plr) local folder = Instance.new("Folder", plr) folder.Name = "leaderstats" local value = Instance.new("IntValue", folder) value.Name = "Cash" currency.Value = 1000 -- starting cash you can change this end)
I hope this helps
Also put this in server storage and use a normal script.
local currencyName = "Cash" local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore") local Players = game:GetService("Players") function onPlayerJoined(Player) local folder = Instance.new("Folder") folder.Name = "leaderstats" folder.Parent = Player local currency = Instance.new("IntValue") currency.Name = currencyName currency.Parent = folder local ID = currencyName.."-"..player.UserId local savedData = nil pcall(function() local savedData = DataStore:GetAsync(ID) end) if savedData ~= nil then currency.Value = savedData print("Data loaded") else currency.Value = 100 print("Players to the game") end end function onPlayerLeft(Player) local ID = currencyName.."-"..Player.UserId DataStore:SetAsync(ID,Player.leaderstats:FindFirstChild(currencyName).Value) end game:BindToClose(function() for i,v in pairs(Players:GetPlayers()) do onPlayerLeft(v) end end) Players.PlayerAdded:Connect(onPlayerJoined) Players.PlayerRemoving:Connect(onPlayerLeft)