Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need help on a save system to save the players money?

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)

2 comments

0

You can do that with datastores. I recommend you to watch some videos on youtube about Datastores.

0

umm thats what i wanna know

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.