Why wont my leaderstats save, and what's wrong with this script?

local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“MoneyStats”)
local Players = game:getService(“Players”)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new(“Folder”,plr)
stats.Name = “leaderstats”
local coins = Instance.new (“IntValue”,stats)
coins.Name = “Coins”
coins.Value = 0
– Heart system
local lives = Instance.new(“IntValue”,stats)
lives.Name = “Lives”
lives.Value = 3

plr.CharacterAdded:Connect(function(character)

  local humanoid = character:WaitForChild("Humanoid")

  humanoid.Died:Connect(function()

  	lives.Value -= 1

  	if lives.Value == 0 then
  		plr.TeamColor = BrickColor.new("White")
  	end

  	local Data = DataStore:GetAsync(plr.UserId)
  	if Data then
  		coins.Value = Data.Coins
  	end
  end)

  game.Players.PlayerRemoving:Connect(function(Player)
  	DataStore:SetAsync(Player.UserId, {
  		["Coins"] = Player.leaderstats.Coins.Value;
  	})
  end)

end)
end)

sorry for the late replie, the forum undergo maintenance and i have to wait. Anyway, this is my solution and the way that i used to save data. Feel free to take a look

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local numberOfPlayers = 0
local MyID
local MyPlayer
game.Players.PlayerAdded:Connect(function(player)
	local playerID = "Player_"..player.UserId
	numberOfPlayers+=1
	if numberOfPlayers == 1 then
		for i,v in pairs(game.Players:GetPlayers()) do
			MyPlayer = v
			MyID = "Player_"..v.UserId
		end
	end
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"
	local cash = Instance.new("IntValue")
	cash.Parent = leaderstats
	cash.Name = "Cash"
	
	local data 
	local success,errormessage = pcall(function()
		data = myDataStore:GetAsync(playerID)
	end)
	if success then
		cash.Value = data
		print("Successful load data")
	else
		print(errormessage)
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local playerID = "Player_"..player.UserId
	numberOfPlayers-=1
	if numberOfPlayers>0 then
		if numberOfPlayers == 1 then
			for i,v in pairs(game.Players:GetPlayers()) do
				MyPlayer = v
				MyID = "Player_"..v.UserId
			end
		end
		local success,errormessage = pcall(function()
			myDataStore:SetAsync(playerID,player.leaderstats.Cash.Value)
		end)
		if success then
			print("Successful saved data")
		else
			print(errormessage)
		end
	end
end)
game:BindToClose(function()
    numberOfPlayers = 0
	local success,errormessage = pcall(function()
		myDataStore:SetAsync(MyID,MyPlayer.leaderstats.Cash.Value)
	end)
	if success then
		print("Successful saved data")
		print(MyPlayer.leaderstats.Cash.Value)
		print(MyPlayer.UserId)
	else
		print(errormessage)
	end
end)

This is most likely because you’re handling money on the client instead of the server. If you add 100,000 dollars or take away 50,000 dollars locally on the client, only you will see those changes. You’ll need to etiher handle it from the server or a remote event, etc.