Outputing as Nil even after being defined properly earlier in the program

the issue is that while making the heart system, I need individual ids for the nodes, this works in the first function and after printing the table, I know for sure the table is normal however im getting an error saying deadheart is nil, the id defined properly for sure

As you see in your first code, that variable is local. That means it’s only accessible to you inside that function.

Also, you are overwriting a lot of self.___ variables in that for loop.
That means you only store the values from the last loop.

2 Likes

Wow I never new that was a thing thank you :pray:

I wrote a post on this subject a while back, the first half explains scoping:

2 Likes