Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What to do with my old game if the Roblox's Table-saving DataStore is deprecated?

So I have an old survival game back in 2017, I've created a DataStore script that saves tables:

You may have the full script here:

local Storage = game:GetService('ReplicatedStorage')
local ItemsFolder = Storage:WaitForChild('ItemsFolder')
local DataStoreService = game:GetService("DataStoreService")
local InventoryData = DataStoreService:GetDataStore("PlayerInventory")
local ItemsList = {}
for i,item in pairs(ItemsFolder:GetChildren()) do
	table.insert(ItemsList,item.Name)
end

game.Players.PlayerAdded:connect(function(plr)
	local scope = "Player_"..plr.UserId
	local InvFolder = Instance.new('Folder')
	InvFolder.Name = "InventoryFolder"
	local PlrItemObj = {}
	
	for i=1,#ItemsList do
		local Newvalue = Instance.new("IntValue")
		Newvalue.Name = ItemsList[i]
		table.insert(PlrItemObj,Newvalue)
		Newvalue.Parent = InvFolder
	end
	
	local DataFile = InventoryData:GetAsync(scope)
	
	if DataFile then
		for i=1,#PlrItemObj do
			print("Name: "..PlrItemObj[i].Name.." / Value:"..PlrItemObj[i].Value)
			PlrItemObj[i].Value = DataFile[i]
		end
	else
		local DataToSave = {}
		for i=1,#PlrItemObj do
			table.insert(DataToSave,PlrItemObj[i].Value)
		end
		InventoryData:SetAsync(scope,DataToSave)
	end
	
	InvFolder.Parent = plr
end)

At the line "PlrItemObj[i].Value = DataFile[i]"

I get this error "attempt to index local 'DataFile' (a number value)"

So is there another way to fix the DataStore?

P/s: If you're suggesting to save the data values one by one then you can't since the game have more than 100 items then it would throttle the firing due to limited DataStoreService requests.

4 comments

1

This code would never have worked with a data store. You save a value in a table which is saved ie {24, 5, 3}. You then index this and try to acces .Name which is incorrect since this data was bit saved. This is for the print statment only.

1

Nothing about datastore tables is deprecated. You've obviously SetAsync a number value in a different script. obv we're not gonna fix that

1

The error is saying that DataFile is a number, but you are treating it as a table. Check where you are saving scope to make sure you are saving it as a table.

0

What does your table look like?

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.