Hi everyone, I’m working on a server-authoritative weapon spawner in Godot 4.5. My goal is simple:
Host waits 5 seconds * Host rolls a dice (60% chance M4A1, 40% Pistol). * Host instantiates the weapon and adds it as a child. * MultiplayerSpawner should replicate this exact weapon to all clients.
The Problem: The clients are sometimes spawning a different weapon than the host (e.g., Host sees M4A1, Client sees Pistol). It seems like the clients might be running their own RNG logic or the MultiplayerSpawner is not syncing the specific scene choice correctly.
*
I couldn’t solve the problem. I consulted ai but it didn’t help. I would be very happy if you could help me.
*
code:
#------------------------------------------------------#
extends Node3D
@export var m4a1_scene: PackedScene
@export var pistol_scene: PackedScene
func _ready():
if multiplayer.is_server():
await get_tree().create_timer(5.0).timeout
spawn_silah()
func spawn_silah():
if not multiplayer.is_server():
return
var sans = randf()
var secilen_silah = null
if sans <= 0.60:
secilen_silah = m4a1_scene.instantiate()
print("Sunucu M4A1 seçti.")
else:
secilen_silah = pistol_scene.instantiate()
print("Sunucu Pistol seçti.")
if secilen_silah:
secilen_silah.global_position = $MeshInstance3D.global_position
add_child(secilen_silah, true)
rpc("mesh_gizle")
@rpc("call_local", "reliable")
func mesh_gizle():
$MeshInstance3D.visible = false