• 2D
  • Invalid set index 'flip_h' (on base: 'null instance') with value of type 'bool'.

Can someone help me? I made an enemy ai moving and its hittable and killable. so I made it move and flip its direction whenever it hits a wall or a player or an enemy. but whenever I try playing it, the error shows: Invalid set index 'flip_h' (on base: 'null instance') with value of type 'bool'. Please Help me Im still learning using Godot.

Here's My Code:

extends KinematicBody2D

const GRAVITY = 10
const SPEED = 30
const FLOOR = Vector2(0, -1)

var velocity = Vector2()

var direction = 1


func _ready():
	pass
	
# warning-ignore:unused_argument
func _physics_process(delta):
	velocity.x = SPEED * direction
	
	if direction == 1:
		$AnimatedSprite.flip_h = false
	else:
		$AnimatedSprite.flip_h = true
		
	$AnimatedSprite.play("SkeletonWalk")
	
	velocity.y += GRAVITY
	
	velocity = move_and_slide(velocity, FLOOR)
	
	if is_on_wall():
		direction = direction * -1


func _on_AnimatedSprite_animation_finished():
	if $AnimatedSprite.animation == "SkeletonDeath":
		queue_free()

Based on the error, I think the issue is that the script isn’t getting the “AnimatedSprite” node in $AnimatedSprite. Does the KinematicBody2D that this script is attached to have a AnimatedSprite child node called “AnimatedSprite”?

8 months later

Twisted I love you. I was having the same issue and this solved it. I was going nuts for 2hrs