DataStore not working

If it doesn’t even print anything then the PlayerAdded function is not working

Try this instead:

local dataStore = game:GetService("DataStoreService"):GetDataStore("SaveData")
local function PlayerAdded(plr)
	wait()
	local plrid = "id_"..plr.UserId
	local save1 = plr.leaderstats.Coins
	local save2 = plr.leaderstats.Gems
	local save3 = plr.leaderstats.Wins
	local save4 = plr.leaderstats.XP
	

	local GetSaved = dataStore:GetAsync(plrid)
	if GetSaved then
		save1.Value = GetSaved[1]
		print("Coins")
		save2.Value = GetSaved[2]
		print("Gems")
		save3.Value = GetSaved[3]
		print("Wins")
		save4.Value = GetSaved[4]
		print("XP")
	else
		local NumberForSaving = {save1.Value, save2.Value, save3.Value, save4.Value}
		dataStore:GetAsync(plrid,NumberForSaving)
	end
end

game.Players.PlayerAdded:Connect(PlayerAdded)

for _, player in ipairs(game.Players:GetPlayers()) do 
    PlayerAdded(player)
end

game:BindToClose(function()
	task.wait(3)
	for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
		dataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.Coins.Value, plr.leaderstats.Gems.Value, plr.leaderstats.Wins.Value, plr.leaderstats.XP.Value})
	end
end)

Was the player ever added from the beginning to the data store?

Like, if it’s their first time player, they’ll be added to the data store?

Still doesnt save anything… are there any other solutionS?

Are you giving yourself 1k coins through the client or through the server? If it’s through the client then it won’t save to the datastore.

Im not giving myself any coins, i have a round system that gives me coins. so that works through the server

I have had this issue to, however it isn’t really a problem.

What I found was that my script was working, but it didn’t save the coins when i gave them to myself via commands.

What I mean by that is, when I manually changed my value in the command console or in the leaderstats folder while playing, it wouldn’t save.

Try putting a part into the workspace that, when touched, gives you money, and see if that works instead.

Post edit: Sorry, did not see your previous response with the round system, i thought you were changing it with commands. Make sure the round system gives you coins on a SERVER script. I will look into this further…

Replace this with the script you’re using to create your leaderstats files. This worked for me.

local dataStore = game:GetService("DataStoreService"):GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(plr)
	local plrid = "id_"..plr.UserId
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Coins = Instance.new("IntValue") -- You can replace IntValue with whatever value you're using to create them.
	Coins.Name = "Coins"
	Coins.Parent = leaderstats
	
	local Gems = Instance.new("IntValue")
	Gems.Name = "Gems"
	Gems.Parent = leaderstats
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats
	
	local XP = Instance.new("IntValue")
	XP.Name = "XP"
	XP.Parent = leaderstats
	
	
	local GetSaved = dataStore:GetAsync(plrid)
	
	if GetSaved then
		Coins.Value = GetSaved["Coins"]
		Gems.Value = GetSaved["Gems"]
		Wins.Value = GetSaved["Wins"]
		XP.Value = GetSaved["XP"]
		print("Player's data restored.")
	else
		local NumberForSaving = {Coins.Value, Gems.Value, Wins.Value, XP.Value}
		dataStore:SetAsync(plrid,NumberForSaving)
		print("Player doesn't have data.")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datatable = {
		Coins = plr.leaderstats.Coins.Value,
		Gems = plr.leaderstats.Gems.Value,
		Wins = plr.leaderstats.Wins.Value,
		XP = plr.leaderstats.XP.Value
	}
	
	dataStore:SetAsync("id_"..plr.UserId, datatable)
end)

Let me know if this works for you.

Maybe you were in client mode, haha

Don’t fix this issue and use profileservice

Your issue can be fixed but will bring more issues to your game if you use setasync

First of all, a player may leave inmediately when he joins making it possible for the setasync to load faster, plus, you don’t have any session locking since you could leave and join back and the previous setasync may not have loaded yet

Still does not save anything unfortunately

How would this work? ive just got into datastoring and ive never heard of that

You can check the documentation or some videos linked there. I highly suggest you to transition to this module and almost always use it. To prevent further headaches in your scripting life

Might it have something with specificly this part to do with?

Why would it have something to do? Also no

I was unsure, that’s why I said, “might it” and put a question-mark at the end.

Couldn’t you have tested that yourself or posted a new topic instead of bumping this thread for a question, not a solution?