userni3
(user)
August 21, 2021, 7:05pm
#1
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
userni3
(user)
August 21, 2021, 7:09pm
#3
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.
userni3
(user)
August 21, 2021, 7:11pm
#5
no, they are all named correctly
Did you say that the variables were “Object Values”?
userni3
(user)
August 21, 2021, 7:12pm
#7
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.
userni3
(user)
August 21, 2021, 7:20pm
#10
no, the tower value is the towers model, not the tower
userni3
(user)
August 21, 2021, 7:21pm
#11
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
userni3
(user)
August 21, 2021, 7:24pm
#13
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
userni3
(user)
August 21, 2021, 7:26pm
#15
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.
userni3
(user)
August 21, 2021, 7:28pm
#17
here it is:
module.Data = {
["Gunner"] = {
["Level1"] = {
["Range"] = 14,
["Damage"] = 1,
["Firerate"] = 1.7,
}
}
}
Is towerupdata assigned to module.Data?
greipster
(human)
August 21, 2021, 7:29pm
#19
You could try and print the value from the table:
print(towerupdata[tower.Parent.Name][level].Range)