Why wont this data store code work?

local DataStoreService = game:GetService(“DataStoreService”)
local GoldStorage = DataStoreService:GetDataStore(“GoldStorage”)

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Gold = Instance.new("IntValue",leaderstats)
Gold.Name = "Gold"

local data = GoldStorage:GetAsync(player.UserId)
if data then
	Gold.Value = data["Gold"]
else
	Gold.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(player)

local function create_table(player)
	local player_stats = {}
	for _, stat in pairs(player.leaderstats:GetChildren()) do
		player_stats[stat.Name] = stat.Value
	end
	return player_stats
end

local sucess, err = pcall(function()
	local player_stats = create_table()
	local userID = player.UserId
	GoldStorage:SetAsync(userID,player_stats)
end)
if not sucess then
	warn('Could not save data')
end

end)

You never passed the player in the create_table() function. Try passing the player as an argument.

Alright, ill try debugging by doing what you just said.

I did that, The program is indeed working and saying that the Data is saving.