Can't clone an object from a function and remote event

Hi I am trying to create a clone of the object, however, the clone seems to be nil…?

Here is my code:

server:

game.ReplicatedStorage.Events.UseItem.OnServerEvent:Connect(function(item, playerid)
	local itemname = game.ServerStorage.Items:FindFirstChild(item)
	local itemclone = itemname:Clone()
	itemclone.Parent = game.Workspace
	
end)

Local:

local function UseItem(item, playerid)
		game.ReplicatedStorage.Events.UseItem:FireServer(item, playerid)
end
	
mouse.KeyDown:Connect(function(key)
	
	if key == "e" then
		if player:FindFirstChild("CurrentItem").Value ~= "None" then
			if player:FindFirstChild("CurrentItem").Value == "Oil Spill" then
					print("Player has oil")
					UseItem("OilSpill", player.UserId)
			end
		end
	end
end)

The OnServerEvent function isn’t fully correct. The callback returns first the player object, and then the other objects you passed from the client.

game.ReplicatedStorage.Events.UseItem.OnServerEvent:Connect(function(player, item, playerid)
	local itemname = game.ServerStorage.Items:FindFirstChild(item)
	local itemclone = itemname:Clone()
	itemclone.Parent = game.Workspace
	
end)
1 Like