Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix: Attempt to index nil with 'Clone'?

So I'm making a custom inventory gui and buttons to equip and unequip tools in their inventory (a folder put into the player; not the deafult Backpack) whenever I click the item gui this error shows up: Players.COOLGUY16T.PlayerGui.BackPack.BackpackFrame.Items.Tool.LocalScript:9: attempt to index nil with 'Clone'.

here is the script (its on the client side)

local clicked = false
local player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	local character = game.Players.LocalPlayer:FindFirstChild("Character")
	local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
	
	local tool = player.Inventory:FindFirstChild(script.Parent.Name):Clone()
	if clicked == false then
		humanoid:EquipTool(tool)
		player.HeldItem.Value = tool.Name
		clicked = true

	else
		tool:Destroy()
		humanoid:UnequipTools()
		player.HeldItem.Value = ""
		clicked = false
		end


end)

I dont know what to do please help!

1 answer

✓ Accepted answer
local Thing = player.Inventory:FindFirstChild(script.Parent.Name)
local tool = Thing:Clone()

2 comments

0

I tried that. Didn't work

1

Wait I just noticed that there was no tool in the inventory! Thanks anyway.

This discussion is preserved as it was. New answers, comments, and votes are closed.