How would I turn my currency system into datastore?

How would I make my currency system code link to datastore service? Remember, I am using a script located in ServerScriptService.

Code

local Players = game:GetService("Players")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Currency = Instance.new("IntValue")
	Currency.Name = "Coins"
	Currency.Value = 0
	Currency.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

°You can use
– local datastore = game:GetService(“DataStoreService”)
– local data1 = datastore:GetDataStore(“Anything breh”)
°After finishing creating the leaderstats, you do like this: (Coins as example)
– Coins.Value = data1:GetAsync(player.UserId) or 0
data1:SetAsync(player.UserId, Coins.Value)
°After that, makes a function of players leaving: – game.Players.PlayerRemoving:Connect(function(plr)
– data1:SetAsync(player.UserId, Coins.Value)

You can edit this to your need:

game.Players.PlayerAdded:Connect(function(player)
local ls = Instance.new(“Folder, player”)
local pts = Instance.new(“IntValue”,ls)
pts.Name = (“Points”)
pts.Value = PTSStore:GetAsync(player, player.leaderstats.Points.Value) or 0
end)

game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
PTSStore:SetAsync(player, player.leaderstats.Points.Value)
end)
if success then
print(“Successfully saved “…player.Name…”'s Data!”)
else
print(“Couldn’t save the user:”…player.Name…“'s Data!”)
warn(err)
end
end)

Do you mind putting this in my code that I have provided above?