Problem accessing variable from instanced scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spu7Nix

So, i have a main scene, and in there i have instance two other scenes (Obstacle and SpeedUp). In each of the instanced scenes i have a variable called “type”, and i want to access this variable from the main scene. This works for one scene (SpeedUp), but not for the other! All i get is the error “Invalid get index ‘type’ (on base: ‘Node2D’)”

Main scene (relevant) code:

for x in grid_size.x:
	for y in grid_size.y:
		if randf() < obstacle_r:
				
			var new_obstacle = Obstacle.instance()
			new_obstacle.position = map_to_world(Vector2(x, y)) + half_tile_size
				
			add_child(new_obstacle)
			grid[x][y] = new_obstacle
			print("type:" + str(grid[x][y].type)) #The error is here
				
				
		elif randf() < speed_r:
				
			var new_speedup = SpeedUp.instance()
			new_speedup.position = map_to_world(Vector2(x, y)) + half_tile_size
				
			add_child(new_speedup)
			grid[x][y] = new_speedup
			print("type:" + str(grid[x][y].type))

Obstacle scene code:

extends Node2D

var grid = get_parent()
var type = 2

SpeedUp scene code:

extends Node2D

var dir = randi() % 4
var grid = get_parent()
onready var sprite = get_node("Sprite")
var type = 3

func _ready():
	rotate(dir * PI / 2)
	pass

Anything i might be doing wrong? Or is this a bug?