DataStore with tables don't work

hi, i was working at a Custom DataStore, all works but i want to make a sistem that saves all the saves the player leave, to can make a anti data lose and to can make to load a old save, but my code don’t work it returns nil but i put if the data is nil to return {}

the code:



function HiddenAddons:GetFromValues(plr,key)
	
	if DSS:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0 then
		
		local data = DSS:GetDataStore(key.."__"..plr.UserId):GetAsync(plr.UserId)
		
		if data == nil then
			data = {}
		end
		
		spawn(function()
			return data
		end)
	else
		wait(10)
		local data = DSS:GetDataStore(key.."__"..plr.UserId):GetAsync(plr.UserId)
		
		if data == nil then
			data = {}
		end
		
		spawn(function()
			return data
		end)
	end
end

May I ask why are you wrapping the return inside the spawn?
That’s a different function, and you are returning inside that function, not the GetFromValues function.
Since nothing is being returned inside the GetFromValues function, you get nil.

To fix this, pull the return data out of the spawn.

why are you doing this in the code?

Also I would not create a datastore per player. Just use one and have a key prefix for the key only.