Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
3 years ago
Edited 3 years ago
local Thing = player.Inventory:FindFirstChild(script.Parent.Name)
local tool = Thing:Clone()
0
I tried that. Didn't work COOLGUY16T 37 — 3y
1
Wait I just noticed that there was no tool in the inventory! Thanks anyway. COOLGUY16T 37 — 3y
Ad

Answer this question