To track the score we will use a Global Script
What is an Autoload / Singleton / Global?
An Autoload is a script or node that Godot loads automatically when the game starts, and—crucially—it never dies.
It is a globally accessible node that persists for the entire duration of the game. We use it for two main things:
Data Persistence: Saving information (like High Scores) that shouldn't disappear when the level restarts.
Global Communication: Allowing distant objects to talk without being directly connected."
Right-Click in the FileSystem
Go to Project Settings => Globals
Click the folder and select the script
Click Add to make it Global
Create signal to tell the UI to
Create a variable to store the current score
Create a function to add to the score
Update the score by the amount
Broadcast the signal to all listeners