Script doesn't check Flip_h in the inspector by script

Godot Version



I was making a platformer game using a tutorial, it had a script that checks flip_h in the AnimatedSprite2D inspector by using the script.
I tried to use the code but it didn’t check the flip_h.

the code i was using:

var isLeft = velocity.x < 0
	AnimatedSprite2D.flip_h = isLeft

i also added this at the beginning of the script after “extends CharacterBody2D”

@onready var animated_sprite_2d = $AnimatedSprite2D

the full code:

extends CharacterBody2D

@export var speed = 300
@export var gravity = 30
@export var jump_force = 700
@onready var animated_sprite_2d = $AnimatedSprite2D

func _physics_process(delta):
if !is_on_floor():
	velocity.y += gravity
	if velocity.y > 1000:
		velocity.y = 1000

if Input.is_action_pressed("jump") and is_on_floor():
	velocity.y = -jump_force

var horizontal_direction = Input.get_axis("move_left", "move_right")
velocity.x = speed * horizontal_direction

var isLeft = velocity.x < 0
animated_sprite_2d.flip_h = isLeft


i accidentally deleted the post but its back

Regular scripts are meant to only affect the game when it is running. If you start your game and Switch the Node Tree to the Remote tab, you will see the tree for the loaded scene with all the changes, and if you navigate there to your sprite, you will see the checkbox should be checked.
If you want to actually affect what you see in the editor when the game is not running you need to use a tool script that starts with @tool, but since you’re using a CharacterBody2D, that is clearly not what you want because that kind of node will not work in tool mode.

What is the tutorial? It seems like it made you confused about the interface instead of explaining it.

I found out that the original player (CharacterBody2D) with the script was saved as a scene and then imported to the scene i want to put the player in, i copied the CharacterBody2D (with scripts and textures) from the scene with only the player and i pasted it to the scene where i wanted the player in, and it somehow works. thanks for the help btw.

edit: i forgot to paste the link to the tutorial i was using: