Hello fellow Godot developers, I'm new to godot and I'm trying to program, without experience, using chat gpt x_x.

I'm currently working on a "multiplayer game" in Godot and have run into an issue with my Camera2D setup. I've successfully implemented a camera that follows the player character, but I'm facing a challenge when it comes to handling multiple clients. The problem is that when I open a second client, the camera remains linked to the first player instead of associating with the new client's character. I'm looking for advice on how to ensure that each client has their own camera associated with their character. Below is the script for my character and server:

extends CharacterBody2D
class_name Character
var _state_machine
var _synced_velocity: Vector2 = Vector2.ZERO

func _enter_tree():
	set_multiplayer_authority(name.to_int())

@export_category("Variables")
@export var _move_speed: float = 64.0  
@export var _friction: float = 0.3     
@export var _acceleration: float = 0.3 
@export_category("Objects")
@export var _animation_tree: AnimationTree = null

func _ready() -> void:
	_state_machine = _animation_tree["parameters/playback"]

func _physics_process(_delta: float) -> void:
	if is_multiplayer_authority():
		_move()
		move_and_slide()
	else:
		velocity = _synced_velocity
	_animate()

func _move() -> void:
	var _direction: Vector2 = Vector2(
		Input.get_axis("move_left", "move_right"),
		Input.get_axis("move_up", "move_down")
	)

	if _direction != Vector2.ZERO:
		if is_multiplayer_authority():
			rpc("sync_movement", _direction, _move_speed)
		_update_animation_direction(_direction)
		velocity.x = lerp(velocity.x, _direction.normalized().x * _move_speed, _acceleration)
		velocity.y = lerp(velocity.y, _direction.normalized().y * _move_speed, _acceleration)
	else:
		if is_multiplayer_authority():
			rpc("sync_movement", Vector2.ZERO, 0.0)
		_update_animation_direction(Vector2.ZERO)
		velocity.x = lerp(velocity.x, 0.0, _friction)
		velocity.y = lerp(velocity.y, 0.0, _friction)

func _update_animation_direction(new_direction: Vector2) -> void:
	_animation_tree["parameters/idle/blend_position"] = new_direction
	_animation_tree["parameters/walk/blend_position"] = new_direction
	_animate()

func _animate() -> void:
	if velocity.length() > 10:
		_state_machine.travel("walk")
	else:
		_state_machine.travel("idle")

@rpc
func sync_movement(new_direction: Vector2, speed: float) -> void:
	_synced_velocity = new_direction.normalized() * speed
	_update_animation_direction(new_direction)
	_animate()

And:

extends Node2D

var peer = ENetMultiplayerPeer.new()
@export var player_scene: PackedScene

func _on_hospedar_pressed():
	peer.create_server(135)
	multiplayer.multiplayer_peer = peer
	multiplayer.peer_connected.connect(_add_player)
	_add_player()

func _add_player(id = 1):
	var player = player_scene.instantiate()
	player.name = str(id)
	call_deferred("add_child", player)

func _on_entrar_pressed():
	peer.create_client("localhost", 135)
	multiplayer.multiplayer_peer = peer

What if you delete the camera from the player scene, then add it via code in Character._ready() only if is_multiplayer_authority()?

(I haven't tried this. I'm just guessing)

    award I added @onready var camera = $Camera2D as Camera2D and func _ready() -> void:
    _state_machine = _animation_tree["parameters/playback"]
    if is_multiplayer_authority():
    camera.make_current()
    IT'S WORKING!

      a year later

      MiroslavH Your screen will follow your player. But in your case if your player is server . You can try to connect another one player)