Item cloning not working for dropping items

Hello,
I wanted to make a dropping system for my inventory.
It works perfect besides of these blocks of code.
It gives me theis type of errors:
ServerScriptService.PickUpItem:45: attempt to index nil with ‘Clone’

The 2 different script for the RemoteFunction are below.

I hope anyone can help.

for i, itemButton in pairs(InventoryGui.ItemList:GetDescendants()) do
	-- Right Click
	if itemButton:IsA("TextButton") then
		itemButton.MouseButton1Click:Connect(function()
			local itemFrame = itemButton.Parent
			local itemValue = Inventory:FindFirstChild(itemFrame.Name)
			if itemValue.Value > 0 then
				local DropItem = DropItem:InvokeServer(itemFrame.Name)
				if DropItem == true then
					if itemValue.Value > 0 then
						itemFrame.Quantity.Text = itemValue.Value
					else
						itemFrame.Visible = false
					end
				end
			end
		end)
	end
end
DropItem.OnServerInvoke = function(player, ItemName)
	local Inventory = player.Inventory
	local item = Inventory:FindFirstChild(ItemName)
	if item then
		if item.Value > 0 then
			item.Value = item.Value - 1
			local itemClone = item:FindFirstChild(ItemName):Clone()
			itemClone.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.LookVector * 6
			itemClone.Parent = game.Workspace
			return true
		else
			return false
		end
	end
end
1 Like

Correct me if I’m wrong, but I’m fairly certain this happens regardless of whether you define it or not.
In fact, I think defining it is even worse, as now you have 2 variables to deal with.

Oops, my bad I completely forgot about that since I don’t really use RemoteFunctions

This is basically returning nil because it’s calling FindFirstChild() inside of the tool which has that name. Meaning unless there’s something inside the tools hierarchy it’ll return nil.

1 Like

I found the problem.
I feel so dumb now.
I reffered to something in the local player but i had to refer to the Replicated Storage :confused:
But anyways, thanks for helping.