Any improvements on datastore script?

Hello! I have written a datastore script and was wondering if anything could be improved on it. Is there anyway to make it more secure/reliable then it already is? Here it is:

local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("ExampleName")

local tries = 3

local dataLoaded
local loadedData
local starterCash

local function Set(plr)
	if dataLoaded then
		local key = plr.UserId
		local data = {
			["Cash"] = starterCash,
			["Level"] = 0,
			["XP"] = 0
		}
		
		local count = 0
		local success, err
		
		repeat
			success, err = pcall(function()
				dataStore:SetAsync(key, data)
			end)
			
			count = count + 1
		until success or count >= tries
		
		if not success then
			warn("Failed to set data. Error code: " .. tostring(err))
			
			return
		end
	else
		warn("Data has not been loaded. Please wait for data to be loaded. Plr name" .. plr.Name)
		
		return
	end
end

local function Get(plr)
	local key = plr.UserId
	
	local count = 0
	local success, err
	
	repeat
		success, err = pcall(function()
			loadedData = dataStore:GetAsync(key)
		end)
		
		count = count + 1
	until success or count >= tries
	
	if not success then
		warn("Failed to read data. Error code: " .. tostring(err))
		
		plr:Kick("Failed to load data, please rejoin.")
		
		return
	end
	
	if success then
		if loadedData then
			dataLoaded = true
			
			return loadedData
		else
			dataLoaded = true
			
			return {
				["Cash"] = starterCash,
				["Level"] = 0,
				["XP"] = 0
			}
		end
	end
end

local function CreateLeaderstats(plr)
    local data = Get(plr)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = plr
	
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Parent = leaderstats
	
	local xp = Instance.new("IntValue")
	xp.Name = "XP"
	xp.Parent = plr
	
	cash .Value = data.Cash 
	level.Value = data.Level
	xp.Value = data.XP
end

players.PlayerAdded:Connect(CreateLeaderstats)
players.PlayerRemoving:Connect(Set)

game:BindToClose(function()
	for i, v in next, players:GetChildren() do
		if v then
			Set(v)
		end
	end
end)

All feedback is appreciated.
Thanks!

local dataLoaded,

if one person’s data hasn’t loaded this variable would become true, for example Player1’s data has not loaded that variable would become true, then if player 2 leaves the game, his data would not be set because of this

Even if the data which didn’t load was for Player1. This is why I reccomond using a table instead which stores which players data has not loaded

On a side note, isn’t this just a copy of https://www.youtube.com/watch?v=owqvZJgBM6Q, anyways in this video I have commented a flaw in the system and you should check it out

Nevermind, checked the video again and realised you made the video lol, you already checked my comment and fixed it, I have a other fix you should implement above