Any way to save Arrays?
Trying to make a leaderboard system that takes in past high scores. Only everytime it saves a new high, the game crashes and I get an error, "Invalid operands 'int' and 'Nil' in operator '>' "
This is my save data script:
extends Node
var save_path = "user://varible.save"
var PersBest = 0
var highScores = [10000, 8000, 6000, 3000, 2000]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Load()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func Save():
var file = FileAccess.open(save\_path, FileAccess.WRITE)
file.store\_var(PersBest)
file.store\_var(highScores)
func Load():
if FileAccess.file\_exists(save\_path):
var file = FileAccess.open(save\_path, FileAccess.READ)
PersBest = file.get\_var(PersBest)
highScores\[0\] = file.get\_var(highScores\[0\])
highScores\[1\] = file.get\_var(highScores\[1\])
highScores\[2\] = file.get\_var(highScores\[3\])
highScores\[3\] = file.get\_var(highScores\[3\])
highScores\[4\] = file.get\_var(highScores\[4\])
else:
Save()
And this is the function in player script where the error occurs:
func _on_kill_timer_timeout() -> void:
Autoload.playing = false
if Autoload.score > SaveData.PersBest:
SaveData.PersBest = Autoload.score
if Autoload.score > SaveData.highScores\[-1\]:
SaveData.highScores\[-1\] = Autoload.score
SaveData.highScores.sort()
SaveData.Save()
queue\_free()
Help is appreciated
Posted Jul 23, 2026, 10:18 AM UTC
016