There seems to be no issues when gunUi is referenced in the script. However, when I try to modify the text of gunLabel, I get the “attempt to index nil with text” error. What could be the reason why the script has no issues with the Gui but with the label?
Semi-colons are usually used in many other programming languages to tell the compiler it’s the end of the line, so it doesn’t cause unexpected errors. It’s not necessary at all in lua, but sometimes you just forget that you don’t need them, or you just prefer the sense of security.
Seems like you’re always trying to access gunLabel regardless of whether it’s been defined or not. You can simply just check if gunLabel exists in the first place:
if gunLabel then
if (cd == 0) then
gunLabel.Text = l.Value;
else
gunLabel.Text = l.Value.." ("..cd..")";
end;
end
Also, for that bit of the code at the top of the while loop, you can just do cd = max(cd-1,0).