function being executed multiple times.

func _on_area_entered(area: Area2D) β†’ void:
queue_free()
area.owner.exp_inc()

for some reason, the function exp_inc() is being executed multiple times.

this is the whole exp_inc() script.

func exp_inc():
if get_tree().paused != true:
var elapsedTimeCount = get_parent().elapsedTime
addedExp = addedExp * (elapsedTimeCount + 1)
print(str(elapsedTimeCount) + " " + str(addedExp))
playerTotalExp += addedExp
%playerInfoUI.playerExpUI(playerTotalExp, expToNextLevel)
if playerTotalExp >= expToNextLevel:
currentPlayerLevel += 1
%playerInfoUI.playerLevelUI(currentPlayerLevel)
expToNextLevel += last10LvlExp
if currentPlayerLevel == next10lvl - 1:
expToNextLevel += last10LvlExp + next10lvl
last10LvlExp = expToNextLevel
if currentPlayerLevel >= next10lvl:
next10lvl += 10
sPopup.sLvlupOptions()
get_tree().paused = true
sPopup.show()
return
get_tree().paused = true
popup.lvlupOptions()
popup.show()

Please put your code between ``` on the lines above and below like this:

```gdscript
#Code here
```

You have multiple things triggering your Area2D. queue_free() happens at the end of the frame, and you are assuming it’s an instant delete. To fix this, you need to disable your CollisionShape2D attached to the Area2D.

@onready var collision_shape_2d = $path/to/CollisionShape2D

func _on_area_entered(area: Area2D) β†’ void:
	collision_shape_2d.disable
	queue_free()
	area.owner.exp_inc()
1 Like

sorry about that. its my first time posting here.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.