The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I've been developing a game that needs a score that updates every second. I fairly new and have seen the timer node which counts down.

Godot version 3.5.1
in Engine by (22 points)

1 Answer

0 votes
Best answer

There are a number of ways to do this. Here's the basics with a Timer.

  • Add a Timer to a sample scene
  • In the inspector, set the timer's wait_time = 1, autostart = true, and one_shot = false
  • Connect its timeout signal to a script containing something like:


var score = 0
func _on_Timer_timeout() -> void:
    score += 1

So, each time the timer "times out" (after 1 second here), it'll call the _on_Timer_timeout() function, which will increment the score. Once that happens, the Timer will automaticlally reset to 1 second and being counting down again, repeating the process.

by (22,674 points)
selected by

As another option (not using a Timer) you could just manage this by hand, via the _process() function. Something like:

var time_out = 1
var time = time_out
func _process(delta: float) -> void:
    if time > 0:
        time -= delta
        time = time_out
        score += 1

I was having trouble with making it print the new score, but all you need todo is change print(score) to text = str(score)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.