I'm pretty new to this, so that's the main reason. Anyway, I have two NumValues inside of the local player's PlayerGui (named Bank and Cash). One is for "Bank" money, and the other is "Cash". I want it so both values save whenever a transaction is made... and if someone has never played before "Cash" defaults to 0, and "Bank" is set to 500. Here's the script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("moneyStore")
game.Players.PlayerAdded:connect(function(player)
local playerGuis = player.PlayerGui:WaitForChild'playerGUIs' --The GUI the variables are in
local cash = playerGuis.ATM.Cash
local bank = playerGuis.ATM.Bank
local key = "player-"..player.userId --Assigns key to each player
local savedMoney = DataStore:GetAsync(key)
if savedMoney then --Checks if player has been to game before
cash.Value = savedMoney[1]
bank.Value = savedMoney[2]
else
local moneySave = {cash.Value, bank.Value} -- Bank defaults to 500, cash to 0
cash.Value = 0
bank.Value = 500
DataStore:SetAsync(key, moneySave)
end
cash.Changed:connect(function() --These update the money whenever a transaction is made
local moneySave = {cash.Value, bank.Value}
DataStore:SetAsync(key, moneySave)
end)
bank.Changed:connect(function()
local moneySave = {cash.Value, bank.Value}
DataStore:SetAsync(key, moneySave)
end)
end)
This doesn't work (it just keeps it at 0 for both values). However, I did test something that sort of gave me a result. I set cash.Value = 0 and bank.Value = 500 right after where I declared the cash and bank variables. That did work. However, it served no purpose because it would just reset to those values every time someone joined.

1 comment
Data Store doesn't work in studio and build mode, so try going to a server.