Data Won't Save!

Hello! I am making a datastore but it doesn’t save the data. I need help!

local DS = game:GetService("DataStoreService")
local RS = game:GetService("ReplicatedStorage")
local ColorData = DS:GetDataStore("Colors")
local GetColor = false
local colorevent = RS.Color

local player = game.Players


player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = plr
	
	local ColorPoints = Instance.new("IntValue")
	ColorPoints.Name = "🎨 Color"
	ColorPoints.Value = 0
	ColorPoints.Parent = leaderstats
	
	colorevent.OnServerEvent:Connect(function(play, common)
		if GetColor == false then
			GetColor = true
			play.leaderstats["🎨 Color"].Value += common
			wait(.5)
			GetColor = false
			
		end
	end)
	
	local Data
	local success, errormsg = pcall(function()
	
		Data = ColorData:GetAsync(plr.UserId.."- Color")
		
	end)
	if success then
		print("Loaded")
		
		plr.leaderstats["🎨 Color"].Value = Data
		
	else
		warn(errormsg)
		
	end
	
	
end)

player.PlayerRemoving:Connect(function(plr)
	local Succes, errormessage = pcall(function()
		ColorData:SetAsync(plr.UserId.."- color", plr.leaderstats["🎨 Color"].Value)

	end)

	if Succes then	
		print('Success!')

	else
		print("Error, data not saved!")
		warn(errormessage)


	end
	
end)

game:BindToClose(function(p)
	for _, playr in pairs(game.Players:GetPlayers()) do
		local ID = "Player_"..playr.UserId
	
		--local ColorVal = p.leaderstats["🎨 Color"].Value
	
	local success, errormsg = pcall(function()
		ColorData:SetAsync(ID, p.leaderstats["🎨 Color"].Value)
		print("Yay, Saved!")
		end)
	
	end
	
end)

I will point out that in this line you are retrieving a DataStore with the player’s UserId followed by “Color”, with a capital C.

However, during the saving process, you are saving it to the player’s UserId followed by “color”, with a lower case C.

DataStores are case-sensitive, so saving a value with a key of “color” and another one with a key of “Color” are two completely separate entries.
Could this be the issue you are facing, considering the user’s data is being saved to a different place from where it is being retrieved from?

1 Like

Oh, I see! So would making those 2 data keys the same. The issue should be fixed?

Oh my! It fixed the error! Really glad that you help that you pointed out my silly error!

Haha, no worries! Small issues like this happen from time to time. Have a good one!

Thank you! It should been marked about 2-3m ago

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.