DataStore saving data help

Hey supper here I need help with saving data I looked some tutorial but some dont explain simply so can you try and explain it nicely

Hi,you can try using Profile Service.

Click here

DataStoreService stores your data and it saves your informations. You need to open api service to use it.
You can make Leaderboard, Inventory save, Money save, Daily prize, Weekly prize and such. I will give you an “Money save” example. Because it is more simple and understandable.

local DataStoreService = game:GetService("DataStoreService") --(We call the DataStoreService)
local DataStore = DataStoreService:GetDataStore("MyDataStore") --Creating our data (to save our infos)

game.Players.PlayerRemoving:Connect(function(Player) -- When Player leaves the game
	local Money = Player.leaderstats.Money.Value
	DataStore:SetAsync("Money",Money) -- Set the DataStore Value(Whatever is your money)
end)

game.Players.PlayerAdded:Connect(function(Player) -- When player joins the game
	
	local leaderstats = Instance.new("Folder") --Creating Leaderstats that you see at right top.
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player -- Set the parent to Player
	local Money = Instance.new("IntValue") --Creating Money (In leaderstats)
	Money.Name = "Money"
	Money.Parent = leaderstats -- Set the parent to leaderstats to be able to see money at right top
	
	if DataStore:GetAsync("Money") then
		Money.Value = DataStore:GetAsync("Money") -- Call your Data value
	else
		Money.Value = 0 -- If no data then set the money to 0
	end
	
end)

Here, i call DataStoreService and create Data that i can save my data.
Using PlayerRemoving event to save data when player left from the game.
And using PlayerAdded event to get data when player joined to the game.
You may set data every second, that is your opinion i decided to set it like this.
And you can use UserID while assigning the Data.

What i did is, i create the data and assign the money value when player leaving from the game. I create the leaderstats and create the money when player is added. Then i get the money data and assign player’s money to the money data. If player doesn’t have money data i assign the player’s money to the zero.

You can create your own data with:

You can set the data with:

You can get the data with:

This is the basics of the DataStore. I hope you like it.

1 Like