How to make a placement system in godot with networking

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

I want to make a placement system reminiscent of mario karts or forza horizon’s placement system (ex. 1st, 2nd, 3rd, etc). It’s for my 2d multiplayer platformer.

Do you have any Idea on what would accomplish this and what I’m doing wrong?
If you need any additional information please feel free to ask.

func get_placement():
    var players : Array = []
    var placement : Array = []
    var playerCount = 0
    var currentPlayerPosition = Vector2.ZERO
    for i in get_children():
        if i is Player:
	        var player = i as Player
	        if player.is_running:
		        playerCount += 1
		    if player == self:  # Store current player's position
			    currentPlayerPosition = player.global_position


    for i in range(playerCount):
	    placement[i] = players[i].global_position.distance_to(current_goal)

    var sortedPlacement = placement.duplicate()

    var myPlacement = -1

    for i in range(playerCount):
         if is_close_enough(currentPlayerPosition.distance_to(current_goal), sortedPlacement[i]):
		myPlacement = i

    if myPlacement != -1:
	    $CanvasLayer/Placement.text = str(myPlacement + 1)
	    $CanvasLayer/Placement.text = ""

    func is_close_enough(a: float, b: float, tolerance: float = 0.001) -> bool:
        return abs(a - b) <= tolerance

Project file if needed.

Mischa | 2023-05-21 00:36

:bust_in_silhouette: Reply From: Mischa

I accomplished it with this script:

func sort_players():

for i in get_tree().current_scene.get_children():
    if i is Player:


func compare_distance_to_goal(a, b):
    var distance_to_a = a.global_position.distance_to(current_goal)
    var distance_to_b = b.global_position.distance_to(current_goal)

if distance_to_a < distance_to_b:
   return true
return false