Multiplayer. I don't know how to give control of the player to the client

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

So, in my code there are 4 created players on stage. Control over each player is given to another player. First, the server gives control, and then the client.
I make a script:

enter code here> 	if get_tree().is_network_server(): # # For the server, give control of players to the other peers.
	if players >= 2:
	if players >= 3:
	if players >= 4:
else : ## For the client, give control of players to itself.
	if players >= 2:
	if players >= 3:
	if players >= 4:

The server gives control correctly, but the client does not receive correctly. As a result, customers control 3 players at once. It is LAN-wifi game. I dont know how correctly give control to he clients. Sorry for my English. Thanks in advance!

:bust_in_silhouette: Reply From: SF123

I don’t know if this helps, but you can take a look at my code from one of my games:

extends KinematicBody2D

const MAXSPEED = 400
const ACCELERATION = 500
const FRICTION = 200

var motion = Vector2.ZERO

onready var player_label = $Label
onready var camera = $Camera2D

func _ready():

func _physics_process(delta):
	if is_network_master():
		camera.current = true
		player_label.rect_position = Vector2(position.x - 60, position.y - 40)
		var input_vector = get_input_vector()
		# print(input_vector)
		apply_movement(input_vector, delta)
		apply_friction(input_vector, delta)
		motion = move_and_slide(motion)

		rpc_unreliable_id(1, "update_player", global_transform)

remote func update_remote_player(transform):
	if not is_network_master():
		global_transform = transform
		player_label.rect_position = Vector2(position.x - 60, position.y - 40)

func get_input_vector():
	var input_vector = Vector2.ZERO
	input_vector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
	input_vector.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
	return input_vector.normalized()

func apply_movement(input_vector, delta):
	if input_vector != Vector2.ZERO:
		motion = motion.move_toward(input_vector * MAXSPEED, ACCELERATION * delta)

func apply_friction(input_vector, delta):
	if input_vector == Vector2.ZERO:
		motion = motion.move_toward(Vector2.ZERO, FRICTION * delta)

func set_player_name ():
	player_label.text = Server.players[int(name)]["Player_name"]