Attempt to index number with number

I want to store player’s data from a table. Here’s the code:

local DataStore = game:GetService("DataStoreService")
local sentodata = DataStore:GetDataStore("Sento")    
	local data ="Folder", player)
	data.Name = "Data"
	local toSave
	local clan ="IntValue", data)
	local money ="IntValue", data)
	local speed ="IntValue", data)
	local strength ="IntValue", data)
	local endurance ="IntValue", data)
	local stamina ="IntValue", data)
	local hunger ="IntValue", data)
	clan.Name = "ClanName"
	money.Name = "Yen"	
	speed.Name = "Speed"
	strength.Name = "Strength"	
	endurance.Name = "Endurance"	
	stamina.Name = "Stamina"
	hunger.Name = "Hunger"
	local success, err = pcall(function()
		toSave = sentodata:GetAsync(player.UserId)
	if success then
		if type(toSave) ~= "table" then
			clan.Value = toSave[1] --Where the error occurred
			money.Value = toSave[2]
			speed.Value = toSave[3]		
			strength.Value = toSave[4]
			endurance.Value = toSave[5]
			stamina.Value = toSave[6]
			hunger.Value = toSave[7]
			clan.Value = 1	
			money.Value = 0
			speed.Value = 16			
			strength.Value = 0
			endurance.Value = 0
			stamina.Value = 0
			hunger.Value = 1						
	local toSave = {clan.Value, money.Value, speed.Value, strength.Value, endurance.Value, stamina.Value, hunger.Value}
		sentodata:SetAsync(player.UserId, toSave)

The output said: “attempt to index number with number”

1 Like

If toSave is not a table why would you try to index it?

1 Like

I tried to change it to:

if toSave then

still that error

Well that doesnt change anything because numbers in lua are still truthy (meaning when converted to a boolean they are true). You probably just wanted type(toSave) == "table"

1 Like