im making a tower defense game, but i keep getting this error:
attempt to compare <= nil with number
this is the code:
function refresh()
print(currentmodel.NextLevel.Value)
print(ctower.Costs[currentmodel.Parent.Name][currentmodel.NextLevel.Value])
dmg.Text = "Damage: ".. currentmodel.Configuration.Damage.Value
range.Text = "Range: ".. currentmodel.Configuration.Range.Value
firerate.Text = "Firerate: ".. currentmodel.Configuration.Firerate.Value
upgrade.Text = "$"..tostring(ctower.Costs[currentmodel.Parent.Name][currentmodel.NextLevel.Value])
end
function Upgrade()
if currentmodel.Level.Value ~= currentmodel.MaxLevel.Value and plr.Stats.Cash.Value >= tonumber(ctower.Costs[currentmodel.Parent.Name][currentmodel.NextLevel.Value]) then
currentmodel = serverUpgrade:InvokeServer(currentmodel)
refresh()
local newRVSize = getTowerRange:InvokeServer(currentmodel)
rangeview.Size = newRVSize
else
upgrade.Text = "Maxxed!"
end
end
also this isnt the full script, currentmodel is a value which holds the towers model, ctower is a module with all the information about towers plr is the localplayer.
it would still error since you’re doing >= or greater than or equals to which is for number only, and it contains a string that’s why it was making errors at the first place, try printing
Yeah well then one of the two values you’re comparing is nil, you need to go back a few steps and look at the origins of both values, see if both of them are not nil and if so make em a valid value to compare
i had to use tostring() because when i put ["1"] it printed 50, which was the price for the upgrade
and i was using currentmodel.NextLevel.Value which is a NUMBER, the table requires a string, not a number.