Issue with Ordered Data store says it saved the value but when you rejoin it did not

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want know why ordered datastore is not saving my value

  2. What is the issue? Include screenshots / videos if possible! Ordered DataStore Says it saves my Value but when i rejoin the game it is not saved

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tried to do a bit of debugging to find the issue but to no sucess

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local DataStoreService = game:GetService("DataStoreService")

local CashDataStore = DataStoreService:GetOrderedDataStore("CashDataStore")

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = leaderstats
	
	local SavedCash
	
	local Sucess,ErrorMessage = pcall(function()
		SavedCash = CashDataStore:GetSortedAsync(true, 5)
	end)
	
	if Sucess then
		print("Sucessfully retrieved data")
	else
		warn(ErrorMessage)
	end
end)

local SavedCash

game.Players.PlayerRemoving:Connect(function(Player)
	local Sucesss,ErrorMessage = pcall(function()
		SavedCash = Player.leaderstats.Cash.Value
	end)
	if Sucesss then
		SavedCash = Player.leaderstats.Cash.Value
		print("Sucessfully Saved Cash Order!")
	else
		warn(ErrorMessage)
	end
end)

Hello, so i’m using ordered data stores to save my data but the problem is that my ordered data store says it sucessfully saved the data when i left the game but when i rejoin it does not save my value how come this is happening?
image
image

you didn’t actually save the cash value to the datastore, it just prints because you tell it to print. To save, you need a key and a value, there’s also an example code at the bottom of this page

game.Players.PlayerRemoving:Connect(function(Player)
	local Sucesss,ErrorMessage = pcall(function()
		CashDataStore:SetAsync(Player.UserId, Player.leaderstats.Cash.Value) --Player.UserId is the unique key, Player.leaderstats.Cash.Value is the value set to the datastore key
	end)
	if Sucesss then
		print("Sucessfully Saved Cash Order!")
	else
		warn(ErrorMessage)
	end
end)