Attempt to index number with 'Name'

Hi, so I am making a datastore script and there is a problem where when the script tries to get the data in a table called “data”, it throws an error called: attempt to index number with 'Name'. I don’t know why this is happening.

Note that I created another topic where a very nice person gave me this datastore code:

--code above maybe not relevant? idk lol
if data then
		-- for data creates values, puts them in playerstats

		--[[ saved table looks like this at the point of writing:
		data = {
			[1] = {
				["Name"] = "Coins",
				["Value "] = 3
			}
			[2] = {
				["Name"] = "DataId",
				["Value"] = 10
			}
		}
		keep in mind its random values, yours will be different, cuz you set them yourself, i picked 2 random ones
		]]
		for _, savedInstance in pairs(data) do
			local Value = Instance.new("IntValue") -- can be changed to bool value, string value, etc.
			Value.Name = savedInstance.Name
			Value.Value = savedInstance.Value
			Value.Parent = playerstats
		end
		dataloaded = true
	else
--rest of code not relevant probably

If you want to see where I insert the data here it is:

local function save(player)
	--make sure that data has actually loaded in (to not clear by accident)
	if dataloaded then
		local key = player.UserId
		local count = 0

		local data = {}

		--adds the name and value of every IntValue in playerstats to the "data" table
		for i, Value in pairs(player.playerstats:GetChildren()) do
			local Thing = {
				["Name"] = tostring(Value.Name),
				["Value"] = tostring(Value.Value)
			}
			table.insert(data, Thing)
		end

		print(data)

Try this for your for loop:

for _, savedInstance in pairs(data) do
	local Value = Instance.new("IntValue")
	Value.Name = savedInstance
	Value.Value = savedInstance.Value
	Value.Parent = playerstats
end
1 Like

Made some progress, but now it is erroring: attempt to index number with 'Value' on the next line

Probably because savedInstance is already the value, remove .Value

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.