Dropping weapon script

local EQUIPMENT = script.parent
function OnUnequipped(EQUIPMENT, player)
EQUIPMENT.SetWorldPosition(player:GetWorldPosition())

end

EQUIPMENT.unequippedEvent:Connect(OnUnequipped)

this script doesn't work

What are you trying to do with this script? If you need to unequip an item you can call the Unequip method from a script to do so, example:

local EQUIPMENT = script.parent
function OnUnequipped(EQUIPMENT, player)
    EQUIPMENT.SetWorldPosition(player:GetWorldPosition())
end
EQUIPMENT.unequippedEvent:Connect(OnUnequipped)

EQUIPMENT:Unequip()

The item is unequiped when player is equiped with another item (Item disappears) and I want when the player is equipped with another item the previous item appears in the position of the player. My script gives Error- ttrying to index a nil field(unequippedEvent)

I forgot to mention, the sample script I wrote assumes that the script is a child of the equipment (hence the line local EQUIPMENT = script.parent). In the hierarchy it would look like this, (don't forget to enable networking for the equipment and script):

Equipment (networked)
|
|----Script (networked)

Error running Lua task: [99F5F22762D1FD44] zadaca script:38: attempt to index a nil value (field 'unequippedEvent')
Error running Lua task: [C7100127D726AFE2] EquipmentAttachObjectToPlayer:43: attempt to call a nil value (method 'Equip')
Error running Lua task: [C7100127D726AFE2] EquipmentAttachObjectToPlayer:52: attempt to call a nil value (method 'Unequip')
Error running Lua task: [C7100127D726AFE2] EquipmentAttachObjectToPlayer:43: attempt to call a nil value (method 'Equip')
Error running Lua task: [C7100127D726AFE2] EquipmentAttachObjectToPlayer:52: attempt to call a nil value (method 'Unequip')

Is the script a child of the equipment and are both the script and equipment networked?

yes, equipment->weapon->script, all networked

Is the script a direct child of the equipment or a direct child of the weapon? If the script is a direct child of the weapon it will not work. local EQUIPMENT = script.parent looks for whatever object is the direct parent of the script.

maybe script.parent.parent?

That works if the script is a child of the weapon which is a child of the equipment.

local EQUIPMENT = script.parent.parent.parent image|690x388

That should work.

local EQUIPMENT = script.parent
local TRIGGER = script.parent:FindDescendantByType("Trigger")

function Drop(equipment)
equipment:Unequip()
-- The pickup trigger needs to be re-enabled (if there is one)
local pickupTrigger = equipment:FindDescendantByType("Trigger")

if pickupTrigger then
    pickupTrigger.collision = Collision.FORCE_ON
end

end

function OnEquipped(equipment, player)
for _, e in ipairs(player:GetEquipment()) do
if e ~= equipment and e.socket == equipment.socket then
Drop(e)
end
end
end

function OnInteracted(trigger, player)
TRIGGER.collision = Collision.FORCE_OFF
EQUIPMENT:Equip(player)
end

EQUIPMENT.equippedEvent:Connect(OnEquipped)
TRIGGER.interactedEvent:Connect(OnInteracted)

this script from learning Api doesn't work too

The script from the learning API uses local EQUIPMENT = script.parent you probably need
local EQUIPMENT = script.parent.parent.parent.