set_meta being buggy

Godot V4.7

set_meta seems to remove from the Life meta data on the second round, and sometimes takes longer to call if other structures are placed on a different round. It’s hard to describe exactly what is happening, but it seems generally messed up. It doesn’t seem as though I can find anything already on the godot forums to help fix my issue.

here is the code for the specific script where the issue is taking place.

extends Panel

@onready var WoodDisplay = get_node("/root/Main/GUI/Resources/Wood/Label")
@onready var StoneDisplay = get_node("/root/Main/GUI/Resources/Stone/Label")
@onready var MetalDisplay = get_node("/root/Main/GUI/Resources/Metal/Label")
@onready var AcornsDisplay = get_node("/root/Main/GUI/Resources/Acorns/Label")
	
var DisplayFormat = "%s: %s/%s"

func ResourceIsOverMax(Type, MaxType):
	if get_meta(Type) > MaxType:
		set_meta(Type, MaxType)

func _process(_delta: float) -> void:
	WoodDisplay.text = DisplayFormat % ["Wood", get_meta("Wood"), GlobalVars.MaxWood]
	StoneDisplay.text = DisplayFormat % ["Stone", get_meta("Stone"), GlobalVars.MaxStone]
	MetalDisplay.text = DisplayFormat % ["Metal", get_meta("Metal"), GlobalVars.MaxMetal]
	AcornsDisplay.text = DisplayFormat % ["Acorns", get_meta("Acorns"), GlobalVars.MaxAcorns]
	
	if Input.is_action_just_pressed("Spacebar"):
		var Wood = get_meta("Wood")
		var Stone = get_meta("Stone")
		var Metal = get_meta("Metal")
		var Acorns = get_meta("Acorns")
		var Types = {"Wood": Wood, "Stone": Stone, "Metal": Metal, "Acorns": Acorns}
		
		GlobalVars.Round +=1
		for StructurePath in GlobalVars.Structures:
			var Structure = get_node(StructurePath)
			var Production = Structure.get_meta("Production")
			var Consumption = Structure.get_meta("Consumption")
			
			var Life = Structure.get_meta("Life")
			var StartLife = Structure.get_meta("StartLife")
			
			var AmountCanConsume = 0
			for key in Consumption:
				if Types[key] >= Consumption[key]:
					AmountCanConsume += 1
			
			if AmountCanConsume == Consumption.size():
				for key in Consumption:
					Wood = get_meta("Wood")
					Stone = get_meta("Stone")
					Metal = get_meta("Metal")
					Acorns = get_meta("Acorns")
					Types = {"Wood": Wood, "Stone": Stone, "Metal": Metal, "Acorns": Acorns}
					set_meta(key, Types[key] - Consumption[key])
				for key in Production:
					Wood = get_meta("Wood")
					Stone = get_meta("Stone")
					Metal = get_meta("Metal")
					Acorns = get_meta("Acorns")
					Types = {"Wood": Wood, "Stone": Stone, "Metal": Metal, "Acorns": Acorns}
					set_meta(key, Types[key] + Production[key])

			#where the Life value is changed
			Structure.set_meta("Life", Life - 1)
			Structure.get_child(1).text = "Life: %s/%s" % [Life, StartLife]
			
			if Life <= 0:
				GlobalVars.Structures.remove_at(GlobalVars.Structures.find(StructurePath))
				Structure.queue_free()
	
	ResourceIsOverMax("Wood", GlobalVars.MaxWood)
	ResourceIsOverMax("Stone", GlobalVars.MaxStone)
	ResourceIsOverMax("Metal", GlobalVars.MaxMetal)
	ResourceIsOverMax("Acorns", GlobalVars.MaxAcorns)
	get_node("/root/Main/GUI/RoundsDisplay").text = "Round %s" % GlobalVars.Round

your for key in consumption loop uses get_meta on this script’s node, not getting meta data from any other node. You really should avoid making such extensive use of metadata, it’s very error prone.

The Life metadata is being grabbed from a different node, so shouldn’t it be unaffected by other uses of metadata in the script?