Error when Copying a code to another Project

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jamecz

Im using Godot 3.0.

In a new project, I’ve copied and pasted a script from another project I did, just a platformer tutorial. However, the script gives me a warning: “Attempt to call function ‘play’ in base ‘null instance’ on a null instance.” Heres the code Im using

        extends KinematicBody2D

const GRAVITY = 5 
const SPEED = 37
const JUMPHEIGHT = -250
const UP = Vector2(0,-1) 

var motion = Vector2()

func _physics_process(delta):
motion.y += GRAVITY

if Input.is_action_pressed("ui_right"):
	motion.x = SPEED
	$AnimationPlayer.flip_h = false
elif Input.is_action_pressed("ui_left"):
	motion.x = -SPEED
	$AnimationPlayer.flip_h = true
	motion.x = 0

if is_on_floor():
	if Input.is_action_pressed("ui_up"):
		motion.y = JUMPHEIGHT
	if motion.y < 0:
	if motion.y > 0:

motion = move_and_slide(motion, UP)
:bust_in_silhouette: Reply From: kidscancode

That error means you tried to call play() on a null variable. Since you’re using $, that implies that you don’t have a node named “AnimationPlayer”.