Invalid get index 'variable' (on base: 'Nil')

Godot Version

v4.2.1.stable

Question

So, I’m currently trying to make a weapons base that I took from a tutorial by StayAtHomeDev (https://www.youtube.com/watch?v=SB0QrnI_-IQ)

I think I’ve completed every step in the tutorial, without fault, but something has to be going wrong.

I’ll list my code below:

And the code of the WeaponBase resource:

An additional issue I’m having is I can’t get the export variable in the first image to show itself within the Inspector dock.

I tried recreating this, but it seems to work fine for me in 4.2.2 (I also reopened it in 4.2.1, but it works there too). Usually if an export variable isn’t showing up in the inspector, it’s because there are errors somewhere in the script that need to be fixed before the list of inspector properties gets updated. I don’t see anything wrong with the code you’ve posted (except perhaps that it doesn’t check if the WEAPON_TYPE variable is set before using it, which would cause the invalid get index error if it is not set during runtime).

Sidenote:
You can post code snippets by putting 3 backticks (`) on their own line before and after the code snippet instead of taking screenshots. It helps with recreating the code locally for those helping so they can copy and paste rather than type it all manually.

What is the exact error message and line it appears on?

edit: ah just noticed it’s a necro’d thread