Welcome to the forums @reapersremorse!
The issue is probably that the coin is colliding with a physics body that is not the player, leading it to crash as it tries to call add_coin
on a node that doesn't have the function available. Given it says it's happening to a StaticBody2D, my guess is that it's a TileMap it's colliding with.
Regardless, you just need to check if body has the function you are looking for before calling it and it should work. So, in Coin.gd
, you'll need to change the _on_Coin_body_entered
function to the following:
func _on_Coin_body_entered(body):
if (body.has_method("add_coin"):
$AnimationPlayer.play("Coin_Bounce")
body.add_coin()
Then it should only call the function on nodes that have the function :smile: