using System.Collections.Generic;
using Mirror;
using UnityEngine;
using MarsFPSKit;
using MarsFPSKit.Weapons;

[RequireComponent(typeof(Collider))]
[RequireComponent(typeof(NetworkIdentity))]
public class Kit_WeaponPickup : NetworkBehaviour
{
    [Tooltip("Weapon ID to give players when picked up.")]
    public int weaponID = -1;

    [Tooltip("Attachments attached to the weapon (optional)")]
    public List<int> attachments = new List<int>();

    [Tooltip("Initial bullets left for this weapon on pickup")]
    public int bulletsLeft;

    [Tooltip("Initial bullets left to reload on pickup")]
    public int bulletsLeftToReload;

    [Tooltip("Delay until respawned after pickup (seconds)")]
    public float respawnDelay = 10f;

    [Tooltip("Prefab asset to respawn")]
    public GameObject weaponPickupPrefab;

    private Vector3 spawnPosition;
    private Quaternion spawnRotation;

    void Awake()
    {
        spawnPosition = transform.position;
        spawnRotation = transform.rotation;

        var col = GetComponent<Collider>();
        if (!col)
        {
            col = gameObject.AddComponent<BoxCollider>();
            col.isTrigger = true;
        }
        else
            col.isTrigger = true;

        if (!TryGetComponent(out NetworkIdentity _))
            Debug.LogError("Kit_WeaponPickup requires a NetworkIdentity.");

        if (weaponPickupPrefab == null)
        {
            weaponPickupPrefab = gameObject;
            Debug.LogWarning("weaponPickupPrefab not assigned, defaulting to self.");
        }
    }

    [ServerCallback]
    void OnTriggerEnter(Collider other)
    {
        Kit_PlayerBehaviour player = other.GetComponentInParent<Kit_PlayerBehaviour>();
        if (player == null) return;

        Debug.Log($"[Kit_WeaponPickup] Player {player.name} triggered pickup {gameObject.name}");

        bool consumed = TryGiveWeaponToPlayer(player);

        if (consumed)
        {
            // Inform RespawnManager and destroy this pickup
            Kit_WeaponPickupRespawnManager.Instance.ScheduleRespawn(weaponPickupPrefab, spawnPosition, spawnRotation, respawnDelay);
            NetworkServer.Destroy(gameObject);
        }
    }

    [Server]
    bool TryGiveWeaponToPlayer(Kit_PlayerBehaviour player)
    {
        if (weaponID < 0 || weaponID >= Kit_IngameMain.instance.gameInformation.allWeapons.Length)
            return false;

        if (player.weaponManagerNetworkData == null)
            return false;

        var runtimeData = player.weaponManagerNetworkData as Kit_ModernWeaponManagerNetworkData;
        var weaponManager = player.weaponManager as Kit_ModernWeaponManager;
        if (runtimeData == null || weaponManager == null)
            return false;

        int slot = weaponManager.HasWeapon(player, weaponID);

        if (slot >= 0)
        {
            var wrData = runtimeData.weaponsInUseDataObjects[slot] as Kit_ModernWeaponScriptRuntimeData;
            if (wrData != null && wrData.bulletsLeftToReload < bulletsLeftToReload)
            {
                int oldAmmo = wrData.bulletsLeftToReload;
                wrData.bulletsLeftToReload += bulletsLeftToReload;
                Debug.Log($"[Kit_WeaponPickup] Refilling ammo for player {player.name} from {oldAmmo} to {wrData.bulletsLeftToReload}");
                return true;
            }
            return false; // Already full
        }
        else
        {
            int[] emptySlots = weaponManager.GetSlotsWithEmptyWeapon(player);
            int targetSlot = emptySlots.Length > 0 ? emptySlots[0] : runtimeData.currentWeapon;
            player.ReplaceWeapon(targetSlot, weaponID, bulletsLeft, bulletsLeftToReload, attachments.ToArray());
            Debug.Log($"[Kit_WeaponPickup] Gave new weapon {weaponID} to player {player.name} on slot {targetSlot}");
            return true;
        }
    }
}

adjust the script, when the player currently picks up the weapon everything works as expected, when the weapon respawns and he picks it up, it succesfully refills his ammo but the weapon is not getting destryoed, it should get destroyed and respawn again after given time in the inspector. This should continue endless, whenever the player or bot picks up the weapon it should change the current weapon to this one (works already) and it should refill the ammo of this weapon (not others, as I think it currently refills all ammo) Show the full fixed script 100%, ready to copy and paste. Keep the prior code and comments, just input the fix