Hi so how Would I be able to make an kill counter

Godot Version

4.2

Question

How would I be able to make a kill counter in an multiplayer game, But it shows up at the screen of the person that died

at the moment I do this

@rpc("any_peer")
func receive_damage():
	health -= 10
	if health <= 0:
                kills += 1
		health = 200
		position = Vector3(0.0, 0.0, 0.1)
	health_changed.emit(health)```
and then

label.text = "kill counter: "+str(kills)```

Seems like you need to add who dealth the damage to the function, or return if they died.

func receive_damage(attacker: Player) -> bool:
    var killed: bool = false
    health -= 10
    if health <= 0:
         attacker.kills += 1
         respawn()
         killed = true
    health_changed.emit(health)
    return killed

hi so after I implemented this, it is giving me an error:

 _process_rpc: RPC - 'CharacterBody3D::receive_damage': Method expected 1 arguments, but called with 

Right you need to supply the attacker to your function call.

it might look something like this

# where `body` is the player being attacked
body.receive_damage.rpc(self)

so I my case something like this

player.receive_damage.rpc(self)
1 Like