I have a script which is meant for each player , ofc its named player.gd 😉.
What ive been always been stuck with multiplayer authorities is the use of is_multiplayer_authority.
I have 2 running instances for testing purposes and is_multiplayer_authority does not do what it means to me,
for example, here in the below script
func _show_UI_elements():
print("Show me what u do")
print(is_multiplayer_authority())
if is_multiplayer_authority():
$"UI elements/Crew".add_child(player_control_scene.instantiate())
$PointLight2D.show()
the last lines is supposed to be only available locally for the player and not visible to anyone else. But , this one here works for server player , but not the client player (localhost). And when I do get_multiplayer_authority and multiplayer.get_unique_id , it always comes out something like 12345678 == 1, how is 1 the unique id? Ive always been stuck with this
extends CharacterBody2D
const MAX_SPEED = 200
@onready var anim = $AnimatedSprite2D
@onready var footsteps = $Footsteps
@onready var start_button_scene = preload("res://scenes/UI_scene/start_button_host.tscn")
@onready var player_control_scene = preload("res://scenes/UI_scene/Player_UI.tscn")
func _enter_tree() -> void:
$Label.text = str(name)
func _ready() -> void:
SignalBus.start_game_pressed.connect(_show_UI_elements)
if (get_multiplayer_authority() == 1 and multiplayer.is_server()):
var start_button = start_button_scene.instantiate()
start_button.name = "StartHostButton"
add_child(start_button)
if not is_multiplayer_authority():
print("This is id controlling", get_multiplayer_authority())
return
func _process(_delta: float) -> void:
update_animation()
if not multiplayer.multiplayer_peer:
return
if not is_multiplayer_authority():
return
var movement_vector = get_movement_vector()
var direction = movement_vector.normalized()
velocity = MAX_SPEED * direction
move_and_slide()
play_footsteps()
flip_sprite(direction.x)
func get_movement_vector():
var x_movement = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
var y_movement = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
return Vector2(x_movement, y_movement)
func update_animation() -> void:
if velocity.length() > 0.1:
if anim.animation != "walk":
anim.play("walk")
else:
if anim.animation != "idle":
anim.play("idle")
func flip_sprite(x_dir: float) -> void:
if abs(x_dir) > 0.01:
anim.flip_h = x_dir < 0
func play_footsteps() -> void:
if velocity.length() > 0.1:
if not footsteps.playing:
footsteps.play()
else:
footsteps.stop()
func _show_UI_elements():
print("Show me what u do")
print(is_multiplayer_authority())
if is_multiplayer_authority():
$"UI elements/Crew".add_child(player_control_scene.instantiate())
$PointLight2D.show()
Here is the same code from above but with a alternate approach to better know whats going behind :
func _show_UI_elements():
print("Show me what u do")
print(get_multiplayer_authority())
print(multiplayer.get_unique_id())
if get_multiplayer_authority() == multiplayer.get_unique_id():
$"UI elements/Crew".add_child(player_control_scene.instantiate())
$PointLight2D.show()
Look specifically at if get_multiplayer_authority() == multiplayer.get_unique_id():
Here is its output :
Show me what u do
(2) 1
Show me what u do
249142064
1
Below is the image with what I mean for server and client :

The left of separation is the client and on the right is the server
Since the client gets no light $PointLight2D.show(), its all black cause the background is black by default