can someone please help me see whats wrong?

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

it says "Attempt to call function ‘rotate_x’ in base ‘null instance’ on a null instance. Heres the code:

extends KinematicBody

var speed = 7
var accelaration = 20
var gravity = 9.8
var jump = 5

var mouse_sensitivity = 0.05

var direction = Vector3()
var velocity = Vector3()
var fall = Vector3()

onready var head = $Head

func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))

:bust_in_silhouette: Reply From: jgodfrey

Your code is hard to read because it’s misformatted in the forums. However, the error is telling you that the object that you’re calling rotate_x() on (your head reference) is not pointing to a valid object.

I see you got that reference with this code:

onready var head = $Head

That syntax is correct, but for it to work, your Head object must be a direct child of the node containing the posted script. If it is not, that reference will fail and you’ll end up with the error you reported.

Without seeing your scene tree, it’s hard to say much more other than your Head reference is currently null.