Good script to save player's data?

Hello! I made a script to save player’s datas. Variable to save call “Money” Can you help me to find errors please?

Ylocal DSS = game:GetService("MoneyDataStore")
local PlayerMoney = DSS:GetDataStore("Money")
game.Players.PlayerAdded:Connect(function(player)
	Player.CharacterAdded:Connect(function(Character)
		local Folder = Instance.new("Folder")
		Folder.Name = "Data"
		Folder.Parent = Player
		
		local Money = Instance.new("FloatValue")
		Money.Name = "Money"
		Money.Parent = Player.Data
		Money.Value = PlayerMoney:GotAsync(Player.userId)
		
		game.Players.PlayerRemoving:Connect(function(Player)
			PlayerMoney:SetAsync(Player.userId, Money.Value)
		end)
		
		while true do
			wait(300)
			PlayerMoney:setAsync(Player.userId, Money.Value)
		end
	end)
end)

Is it saving data or not?(you just said help me find errors)

I think you meant, GetAsync not, GotAsync. UserId, not UserId.

Move that function outside of the PlayerAdded event.

Yeah I believe this also somewhat belongs in Code Review rather than scripting support as the code seems to have been “completed”.

Anyways try out this resource, perhaps this will help you test out your data service needs and find errors yourself.

Hello! I moved my thread. It’s now in code rewiew!

It’s not :GotAsync()

It’s GetAsync()

Hi, I’ve sent this back to Scripting Support. While hypothetically it does fit in the Code Review category because it’s asking for potential improvements, the category isn’t actually supposed to be used like the Cool Creations category (which is what a lot of developers have been doing lately and it’s become very unscalable to move all of the offending threads out).

The Code Review category is not meant to be a debugging category, so your code should already be tested and working by the time it is posted to the category. You have many tools to perform these tests yourself, including reading over the code yourself before starting test sessions. Additionally, you should also know exactly what you’re looking for improvements on, not general feedback. The category guidelines has more information on how to use the category more appropriate.

Have you looked in the output window for errors?

No, the only error I saw concerns another script which had nothing to do with this one.