Multiple Players Share One Leaderstat

so I asked ChatGPT for the base script and i just need help modifying it
(both single player saving and multiple player saving dosent work)

local DataStoreService = game:GetService("DataStoreService")
local leaderstatName = "Money"  -- Replace with your leaderstat name

local dataStore = DataStoreService:GetDataStore("SharedLeaderstats")  -- Name of the DataStore

-- Function to synchronize leaderstat values among players
local function synchronizeLeaderstats(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then
		leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
	end

	local moneyStat = leaderstats:FindFirstChild(leaderstatName)
	if not moneyStat then
		moneyStat = Instance.new("NumberValue")
		moneyStat.Name = leaderstatName
		moneyStat.Value = 0  -- Set initial value
		moneyStat.Parent = leaderstats

		moneyStat.Changed:Connect(function(newValue)
			if typeof(newValue) == "number" then
				local key = "Money_" .. player.UserId  -- Create a unique key for the player
				dataStore:SetAsync(key, newValue)
			end
		end)
	end
end

-- Function to save leaderstat value to DataStore
local function saveLeaderstat(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		local moneyStat = leaderstats:FindFirstChild(leaderstatName)
		if moneyStat then
			local key = "Money_" .. player.UserId  -- Create a unique key for the player
			dataStore:SetAsync(key, moneyStat.Value)
		end
	end
end

-- Synchronize leaderstats when a player joins the game
game.Players.PlayerAdded:Connect(function(player)
	synchronizeLeaderstats(player)
end)

-- Save leaderstats when a player leaves the game
game.Players.PlayerRemoving:Connect(function(player)
	saveLeaderstat(player)
end)

The first problem occurs in the saveLeaderstat function. Change

local moneyStat = leaderstats:FindFirstChild(leaderstatName)

to

local moneyStat = leaderstats:WaitForChild(leaderstatName)

and the other problem is because when players join, they dont have any leaderstats folder, so there is no need to check if there is one or not, and so you are checking with the if statement if there is something called “Money” inside leaderstats(which there never will be), and then if there isnt one, then setting the value of moneystat to 0, which will effectively always set the moneystat to 0 for everyone once they join.

What I would do is remove these if statements, and just make the leaderstats folder, add the money numbervalue and set its value to whatever the datastore value was.