Referring to elements within a table?

I’m trying to make a script which unloads data from a table of save data here is the section of the script in question:

local all = {}
	
	all=StatsStore:GetAsync(Player.UserId)
	
	if all then -- unload data
		currency.Value = StatsStore[1] -- 1 is not a valid member of DataStore
		wins.Value = StatsStore[2]
		XP.Value = StatsStore[3]
		Level.Value = StatsStore[4]
	end
	ChestData.Value=true

The table is loaded in perfectly fine, showing (0, 0, 0, 0) when the mouse is hovering over “all”, although when the script is asked to unload the data from the table, I get this error:

1 is not a valid member of DataStore "DataStoreService.:Stats"  -  Server - Saving:98

What can I do to make it so that the table retrieves the data from the respective entries?

You’re trying to index the data from the DataStore rather than result of GetAsync, try replacing StatsStore[1-4] with all[1-4].

1 Like