Datastore isn't saving?

There are absolutely no errors. I am unable to figure out why it is not saving

local DataStore = game:GetService("DataStoreService")
local data1 = DataStore:GetDataStore('Survivals')
local data2 = DataStore:GetDataStore('Coins')
local data3 = DataStore:GetDataStore('XP')
local data4 = DataStore:GetDataStore('Gem')

game.Players.PlayerAdded:Connect(function(player)
	local defaultMax = 25
	
	local xpHolder = Instance.new("Model")
	xpHolder.Name = 'XPMODEL'
	xpHolder.Parent = player

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

	local money = Instance.new('IntValue')
	money.Name = 'Coins'
	money.Parent = folder
	
	local currency = Instance.new("IntValue")
	currency.Name = 'Survivals'
	currency.Parent = folder
	
	local xP = Instance.new('IntValue')
	xP.Name = 'EXP'
	xP.Parent = xpHolder
	xP.Value = 0
	
	local gemCur = Instance.new("IntValue")
	gemCur.Parent = player
	gemCur.Name = 'Gems'
	gemCur.Value = 0
	

	local maxExp = Instance.new("IntValue")
	maxExp.Name = 'MaxExp'
	maxExp.Parent = player
	maxExp.Value = 25
	
	local level = Instance.new('IntValue')
	level.Name = 'Level'
	level.Value = 1
	level.Parent = player
	
	local maxInc = Instance.new('IntValue')
	maxInc.Name = 'maxInc'
	maxInc.Value = defaultMax
	maxInc.Parent = player
	
	money.Value = data1:GetAsync(player.UserId) or 0
	data1:SetAsync(player.UserId, money.Value)
	
	currency.Value = data2:GetAsync(player.UserId) or 0
	data2:SetAsync(player.UserId, currency.Value)
	
	xP.Value = data3:GetAsync(player.UserId) or 0
	data3:SetAsync(player.UserId, xP.Value)
		
	gemCur.Value = data4:GetAsync(player.UserId) or 0
	data4:SetAsync(player.UserId, gemCur.Value)
	
		game.Players.PlayerRemoving:Connect(function()
		data1:SetAsync(player.UserId, money.Value)
		data2:SetAsync(player.UserId, currency.Value)
		data3:SetAsync(player.UserId, xP.Value)
		data4:SetAsync(player.UserId, gemCur.Value)
	end)
end)
1 Like

There is a max datastore queue limit to how many SetAsync()s you can do. Since you are sending so many, ROBLOX takes either forever to save it or doesn’t at all.

Instead of using so many datastores, just use 1 and use a table to store the data. What you’re currently doing is inefficient.

1 Like

So I’ve heard… I actually attempted saving with tables, but I just got confused. Is it possible you could lead me in the correct direction with the table saving?

You just store a table inside of the datastore. You can call the variables inside of it by doing Table.Variable (Variable is just a placeholder).

1 Like

Here’s a video that might help you(I chose this video because I was the closest representation to your script that I could find).

1 Like

What @zQ86 means, is to save Player’s data in a table and save it using only one function of :SetAsync() instead of four different functions. They also meant to simply use one Data Store, as multiple will probably cause you to lose track when saving Data.

Here is a snippet of what you’re could should resemble.

local DSS = game:GetService("DataStoreService")
local Storage = DSS:GetDataStore("#^$^#^$^$@^%@$&@@&@^%$@^")

game.Players.PlayerAdded:Connect(function(player)
	local defaultMax = 25
	
	local xpHolder = Instance.new("Model")
	xpHolder.Name = 'XPMODEL'
	xpHolder.Parent = player

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

	local money = Instance.new('IntValue')
	money.Name = 'Coins'
	money.Parent = folder
	
	local currency = Instance.new("IntValue")
	currency.Name = 'Survivals'
	currency.Parent = folder
	
	local xP = Instance.new('IntValue')
	xP.Name = 'EXP'
	xP.Parent = xpHolder
	xP.Value = 0
	
	local gemCur = Instance.new("IntValue")
	gemCur.Parent = player
	gemCur.Name = 'Gems'
	gemCur.Value = 0

	local maxExp = Instance.new("IntValue")
	maxExp.Name = 'MaxExp'
	maxExp.Parent = player
	maxExp.Value = 25
	
	local level = Instance.new('IntValue')
	level.Name = 'Level'
	level.Value = 1
	level.Parent = player
	
	local maxInc = Instance.new('IntValue')
	maxInc.Name = 'maxInc'
	maxInc.Value = defaultMax
	maxInc.Parent = player
	
	money.Value = data1:GetAsync(player.UserId) or 0
	
	currency.Value = data2:GetAsync(player.UserId) or 0
	
	xP.Value = data3:GetAsync(player.UserId) or 0
		
	gemCur.Value = data4:GetAsync(player.UserId) or 0
	
	game.Players.PlayerRemoving:Connect(function()
		Storage:SetAsync(Player.UserId.."~Data", {money.Value, currency.Value, xP.Value, gemCur.Value})
	end)
end)
1 Like

That’s not how anything works. Why would other developers be able to alter your data? That makes no sense at all.

1 Like

Let me reword what I said.

If you set the DataStore name to something like “XP”, it is easy for other Developers to use that DataStore name also since it’s common. This will only happen if the keys they use

Storage:SetAsync(Player.UserId.."~Cash", 0)
       this part ^^^^^^^^^^^^^^^^^^^^^^

are the same.

Datastores are exclusive to their universe, if another developer uses the same name, they won’t change eachother.

3 Likes

Oh. My bad, I didn’t know they were exclusive, I thought they weren’t. Sorry.

No issues. I just thought that’s how DataStores worked.

My bad, got you mixed up with the original post creator.