So my problem is that I need to save the amount of money that a player has so that when the player joins again the player's money will be saved. This is my code, any help would be appreciated.
local function addBoard(player) local board = Instance.new("Folder", player) board.Name = "leaderstats" local money = Instance.new("IntValue", board) money.Name = "Money" end game.Players.PlayerAdded:Connect(addBoard)
local DataStore = game:getService("DataStoreService") local MoneyStore = DataStore:GetDataStore("MoneySaveSystem") game.Players.PlayerAdded:connect(function(Player) local leaderstats = Instance.new("Folder", Player) leaderstats.Name = "leaderstats" local Money= Instance.new("IntValue", leaderstats) Money.Name = "Money" Money.Value = MoneyStore:GetAsync(Player.UserId) or 0 MoneyStore:SetAsync(Player.UserId, Money.Value) Money.Changed:connect(function() MoneyStore:SetAsync(Player.UserId, Money.Value) end) game.Players.PlayerRemoving:connect(function(Player) MoneyStore:SetAsync(Player.UserId, Player.leaderstats.Money.Value) end) end)
Hope its can help you