DataStoring doesn't work

local Players = game:GetService("Players")
local DataStoreServices = game:GetService("DataStoreService")
local MyData = DataStoreServices:GetDataStore("Player_Upgrades")

Players.PlayerAdded:Connect(function(Player)

	local Player_Key = "Key_ "..Player.UserId
	
	local Data = MyData:GetAsync(Player_Key)
	
	print(Data)
	
	local Folder2 = Player:WaitForChild("Stats")
	
	if not Folder2 then
		
		Folder2 = Player:WaitForChild("Stats")
		
	end

	local CL = Instance.new("NumberValue")
	CL.Name = "Level_CoolDown"
	CL.Parent = Folder2
	
	if Data then
		CL.Value = Data[1]
	else
		CL.Value = 1
	end
	
	CL.Changed:Connect(function()
		MyData:SetAsync(Player_Key, {CL.Value})
	end)

end)

Players.PlayerRemoving:Connect(function(Player)

	local Player_Key = "Key_ "..Player.UserId
	
	local Folder2 = Player:FindFirstChild("Stats")

	local Values = {Folder2.Level_CoolDown.Value}

	local Success, Errorm = pcall(function()
		MyData:SetAsync(Player_Key, Values)
	end)

	if not Success then
		print(Errorm)
	end

end)

I dont know the issue, all the datastore but this one doesn’t.

What’s the issue here? Any output errors?

Also, I suggest you check out ProfileService instead of using the default Roblox DataStore.

I’m pretty sure it saves, but it saves the first value before not saving anymore for now on.

So the second time you change CL value directly, it just won’t save anything?

When CL first gets saved from the DS. It will no longer get saved anymore, like if you rejoin the game, you get 1 in the value.

Weird, that is impossible to happen unless for whatever reason the returned data was nil.

Unless I’m missing something but have you tried testing it outside of Roblox Studio?

Yes, but it doesn’t work for some reason.