problem whit score

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By crow_dev

I’m trying to create a score to make a pong game but the player’s score starts at 2 and the enemy’s at 1 when I put 0 in the variables

extends Node

var playerscore = 0
var oponentscore = 0

func _on_meta_derrota_body_entered(body):
$pelota.position = Vector2(640, 360)
$oponent.position = Vector2(1243, 364)
$jugador.position = Vector2(44, 364)
oponentscore += 1
get_tree().call_group(‘pelota’ , ‘stop_pelota’)
$Timer.start()

func _on_meta_victoria_body_entered(body):
$pelota.position = Vector2(640, 360)
$jugador.position = Vector2(44, 364)
$oponent.position = Vector2(1243, 364)
playerscore += 1
get_tree().call_group(‘pelota’ , ‘stop_pelota’)
$Timer.start()

func _process(delta):
$playerscore.text = str(playerscore)
$oponentscore.text = str(oponentscore)
$Timer.text = str(int($Timer.time_left))

func _on_Timer_timeout():
get_tree().call_group(‘pelota’ , ‘restart_pelota’)

:bust_in_silhouette: Reply From: Inces

Are You sure bodies other than pong ball aren’t colliding with goal fields ? :wink: Like players ? :wink:
You can always add condition under those two signals to ensure only ball triggers collision :

func onmetaderrotabodyentered(body):
        if body == get_node("Ball") #path leading to your ball

or:

if body is ball #if You made ball a class