Attempt to index nil with number

so, im making a tower defense game, and im trying to make the towers be able to be upgraded, i have all the data about what the range, firerate and damage the towers should have when they get upgraded, but i just cant figure out how to set them. theese are the lines of code that set the range, damage and firerate to the ones from the module:

tower.Configuration.Range.Value = towerupdata[tower.Parent.Name][level].Range
tower.Configuration.Damage.Value = towerupdata[tower.Parent.Name][level].Damage
tower.Configuration.Firerate.Value = towerupdata[tower.Parent.Name][level].Firerate

i keep getting the error:

Attempt to index nil with number

i am confused

With this amount of data, I can’t really be very helpful.

Could you share additional details, such as a where you created the values.

1 Like

the level value is a value sent by the client, aswell as the tower value which is a object value that is set to the towers model by the server, and towerupdata is the tower upgrade data module

I assume the error is referring to one of the configuration variables not existing?

You could try to check that the names are written correctly.

no, they are all named correctly

Did you say that the variables were “Object Values”?

the range, firerate and damage values are number values, the only object value is the tower value, which is sent to the server by the client

Could it be, that you meant to say:

tower.Parent.Configuration.Range.Value = number

Instead of:

tower.Configuration.Range.Value = number

The error you’re getting implies that the towerupdata doesn’t have an index of the tower’s name.

no, the tower value is the towers model, not the tower

but i checked, and it does have the towers name

Have you tried debugging with print statements? Something like

print(towerupdata[tower.Parent.Name]);
tower.Configuration.Range.Value = towerupdata[tower.Parent.Name][level].Range
tower.Configuration.Damage.Value = towerupdata[tower.Parent.Name][level].Damage
tower.Configuration.Firerate.Value = towerupdata[tower.Parent.Name][level].Firerate

Might help if it prints nil

it does print nil, but on the module, it says the name of the tower, but i did set the tower value to the towers model on the server

Then that’s the problem. try

print(tower.Parent.Name)

See if there’s a typo or something like that

it prints nil and the towers name

So that means that the tower’s name doesn’t exist in the towerupdata, are you sure it’s in there? Send the code snippet of where it is in the module.

here it is:

module.Data = {
	["Gunner"] = {
		["Level1"] = {
			["Range"] = 14,
			["Damage"] = 1,
			["Firerate"] = 1.7,
		}
	}
}

Is towerupdata assigned to module.Data?

You could try and print the value from the table:

print(towerupdata[tower.Parent.Name][level].Range)

no it isnt, is that why?

(extra)