Datastores, data in game is different then what is being returned in studio

I am using DataStore2, when using DataStore2(“Data”, Player):Get() in studio it returns the correct player data. If I run that command in game it returns the default data that I have set for the players.

If it helps here is the code I’m using to set the players data when they join.

game.Players.PlayerAdded:Connect(function(Player)
	
	--- SET DEFAULT DATA
	DS2.Combine("PlayerData", "Data")
	if DS2("Data", Player):Get() == nil then
		DS2("Data", Player):Set(DefaultData)
	end
	local OldTable = DS2("Data", Player):Get()
	local Found = false
	for key, value in next, OldTable.Inventory.Accessories do
		if value == "None" then
			Found = true
			break
		end
	end
	if not Found then
		table.insert(OldTable.Inventory.Accessories, "None")
		DS2("Data", Player):Set(OldTable)
	end
	DS2:SaveAll(Player)
	print("Data for "..Player.Name.." set and saved")
end)

The problem is the data in game is always the default data, the data returned in studio is the correct data, any ideas?

2 Likes

Is your data being saved? That is very odd. Is it printing?

DS2 saves the data for you when the player leaves the game, it does print and if you manually print out the data it returns the default array which gets set if you don’t have any data. I printed out the data in studio and it returned all of the players data, i printed it out in game and it returned just the default data.

One thing I have noticed while testing is that sometimes while playing in studio it returns the default data and sometimes it returns the correct data, I’m wondering if I missed something in the documentation or if there’s an issue with cached data being empty but the datastores still contain the correct data. The method I’m using to get players data returns what’s in cache.