Client object not replicating onto server

  1. What do you want to achieve?
    I want to delete an object on client for all clients.
  2. What is the issue?
    The issue is that the object is returning nil on the server.

In a local script I am sending the object value to the server:

DestroyObject:FireServer(mtarget,mtarget.Name)

Then receiving it in a server script:

destoryFunction.OnServerEvent:Connect(function(player,object,name)
	if object ~= nil then
		AllClientsDestroy:FireAllClients(player,object,name)
		gold:FireClient(player,name)
		local clonedWeapon = game.ReplicatedStorage.Tools[name]:Clone() 
		clonedWeapon.Parent = player.Backpack
		local clonedWeapon2 = game.ReplicatedStorage.Tools[name]:Clone() 
		clonedWeapon2.Parent = player.StarterGear
	end
end)

The problem is that the object is nil on the server but isn’t on the client. Why isn’t the object value being replicated onto the server? Is it because the object value only exists on the client and not on the server? Is there a way around this?

Clients cant send objects to the server due to FE. What I usually do is the send the object’s name to the server and search for the object using the name on the server. Also if the client created the object then the object won’t exist on the server.

Thanks for the quick response, but how would I deal with this problem if there is multiple of the same item? Searching in the server using the name would not destroy the specific item, but one at random.

You could loop through the children of workspace and check if the item name is the same on the server.

for i,v in pairs(game.Workspace:GetChildren()) do 
   if v.Name == [name of part] then
       v:Destroy()
   end
end