I just tested your code and it seems to work as intended. So, I can only assume that you’re not actually calling save_highscore()? At least you’re not calling it in the code you posted.
extends Control
const SAVE_FILE_PATH = "user://savedata.save"
func game_over():
visible = true
if Globals.Score > Globals.highscore:
Globals.highscore = Globals.Score
save_highscore()
$VBoxContainer/Best.text = "Best " + str(Globals.highscore)
func save_highscore():
var save_data = File.new()
save_data.open(SAVE_FILE_PATH, File.WRITE)
save_data.store_var(Globals.highscore)
save_data.close()
func load_highscore():
var save_data = File.new()
if save_data.file_exists(SAVE_FILE_PATH):
save_data.open(SAVE_FILE_PATH, File.READ)
Globals.highscore = save_data.get_var()
save_data.close()
really? when i close the game and start again the Best is 0
im not sure but maybe it has something to do with this: