Godot Version
4.3
Question
This is my script :
extends CharacterBody2D
@onready var puzle2 = preload("res://Scenes/Puzzle2.tscn")
@onready var label: Label = $Label
@onready var Score: Label = $Label2
@export var speed = 2
var jump_force = -400
var gravity = 500
var move_distance = 3
var random
var score = 0
var my_velocity = Vector2()
func _pick_new_key():
random = randi_range(1, 5)
func _ready():
my_velocity.x = speed
_pick_new_key()
func _physics_process(delta):
Score.text = "score:" + str(score)
if random == 1:
label.text = "Press D"
if random == 2:
label.text = "Press A"
if random == 3:
label.text = "Press space"
if random == 4:
label.text = "Press W"
if random == 5:
label.text = "Press F"
if random == 1 and Input.is_action_pressed("Button1"):
_pick_new_key()
score += 100
if random == 2 and Input.is_action_pressed("Button2"):
_pick_new_key()
score += 100
if random == 3 and Input.is_action_pressed("Button3"):
_pick_new_key()
score += 100
if random == 4 and Input.is_action_pressed("Button4"):
_pick_new_key()
score += 100
if random == 5 and Input.is_action_pressed("Button5"):
_pick_new_key()
score += 100
if is_on_floor() and Input.is_action_pressed("ui_up"):
velocity.y = jump_force
move_and_slide()
if not is_on_floor():
velocity.y += gravity * delta
else:
my_velocity.y = 0
position.x += speed
move_and_slide()
and I am getting the error: Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.
this is my scene tree