Attempt to index method "Clone" (a nil value)

Hi, so I’ve had this issue where people were on the occasion randomly losing items on their base. I have been FINALLY provided with an error to do with the data module by 1 of the players; however, said error confuses me.

Here’s a copy of the base load script.

function DataLib.TableToBase(Player, Table, Target)
local Baseplate = Target.Baseplate
local BaseCorner = Baseplate.CFrame * CFrame.new(Vector3.new(Baseplate.Size.X / 2, 0, Baseplate.Size.Z / 2))
for i, Object in pairs(Table) do
	if Object.ItemName ~= nil then
		local Item
		if game.ReplicatedStorage.Items:FindFirstChild(Object.ItemName) then
			Item = game.ReplicatedStorage.Items[Object.ItemName]
		else
			Item = ItemFromId(Object.ItemName)
		end
		local HitboxDirection = Vector3.new()
		local DirectionValue = Object.Position[4]
		if Player ~= nil then
			if Item ~= nil then
				Item = Item:Clone()
				Item.Parent = Target.ItemHolder
				local Position = BaseCorner * Vector3.new(Object.Position[1], Object.Position[2], Object.Position[3])
				local lookVector = Vector3.new(Object.Position[4], Object.Position[5], Object.Position[6])
				local CoordinateFrame = CFrame.new(Position, Position + (lookVector * 5))
				Item:SetPrimaryPartCFrame(CoordinateFrame)
				if Item:FindFirstChild("Drop") then
					for i,v in pairs(Item:GetChildren()) do
						if v:FindFirstChild("DropScript") and Player.Difficulty.Value == "Nightmare" then
							v.DropScript.DropStats.DropDelay.Value = Item.Drop.DropScript.DropStats.DropDelay.Value * 3
						end
					end
				end
				SetScriptToggle(Item, false)
				if Item.Information:FindFirstChild("Producing") then
					Item.Information.Producing.Value = true
				end
			else
				print("Item with ID " .. Object.ItemName .. " could not be found!")
			end
		end
	end
end
end

The issue occurs when I clone the Item:

Item = Item:Clone()

Does anyone have any idea why this error occurs? Thanks for any help.

try debugging by printing Item.

Item:GetFullName(),typeof(Item)

I assume it’s an issue with

else
	Item = ItemFromId(Object.ItemName)
end

not returning an instance, so it can’t be cloned

Except I have the check as to whether or not it’s nil already.

just found an error on my part, it returns “N/A”. im so dumb i want to die

1 Like

Happens to everyone ¯_(ツ)_/¯
Glad I could help

Welcome to the club where scripters make dumb mistake and try to figure it out for hours, days, weeks, months, or even years.

Don’t stress out it’s normal for this to happen, it happens to everyone.

4 Likes

While we have you here, consider installing Lightshot or ShareX

2 Likes

oh i didnt take the picture, one of my players did