I am making a Magic bar tied to some IntValues, but every time I try to check for a difference between two values (to start regenerating Magic), the game outputs an error.
Code :
Magic = script.Parent
MagicRegen = Magic.MagicRegen
MaxMagic = Magic.MaxMagic
Level = Magic.Parent.Level
wait(1)
Bar = game.Players.LocalPlayer.PlayerGui.HeadsUpDisplay.Main.Magic
MaxMagic = {
100, 115, 130, 150, 175, 200, 230, 265, 305, 350,
405, 465, 535, 615, 710, 815, 935, 1075, 1240, 1425
}
while wait(.1) do
if Magic.Value < MaxMagic.Value then
Magic.Value = Magic.Value + (MagicRegen.Value / 10)
end
Bar:TweenSize(UDim2.new(0, 20, 0, (Magic.Value * 100)/MaxMagic.Value * -1), 1, 1, .1)
end
Error : 17:17:58.009 - Players.Player1.Backpack.Statistics.Values.Magic.MagicHandler:17: attempt to compare number with nil 17:17:58.012 - Stack Begin 17:17:58.013 - Script 'Players.Player1.Backpack.Statistics.Values.Magic.MagicHandler', Line 17 17:17:58.014 - Stack End
Any help will be appreciated!
- TheArmoredReaper

6 comments
idk, but why are u using 7 numbers in the tween?. doesnt it only need 4
The first four are the EndSize, then comes EasingDirection, EasingStyle, and Time. EndSize uses UDim2 (4 values), and the others use one value each. Remember that Enums can be numbers or strings.
I see your mistake, you changed the MaxMagic variable on line 11 to a table. Since there is no .Value index of the MaxMagic table, the script errors saying that it's nil. What exactly are you trying to do so I can help answer your question.
Oh, thank you. I did not plan on using the same name, it happened unconsciously. I will fix it now. Publish your answer as an Answer so I can select it please.
Just rename the table to something other then MaxMagic so the rest of the script can run.
Now it runs perfectly! I had made a mistake with the names... :S