Attempt to index nil with clone

  1. What do you want to achieve? Keep it simple and clear!

I am trying to make a script that when you pick-up the item then you craft the object and when you click it goes into a folder in ReplicatedStorage.

  1. What is the issue? Include screenshots / videos if possible!

it gives me error in the output and it says attempt to index nil with clone

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I try looking through the devforum for solutions and on the internet but nothing.

I would be really appreciative if someone could help me with this.
Thank you! :slight_smile:

lua local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Structures = ReplicatedStorage:WaitForChild("Items")

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local StructureFrame = game.Players.LocalPlayer.PlayerGui.MainGui.InventoryGui.ItemList
local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")

local mouse = player:GetMouse()

local yBuildingOffset = 5
local maxPlacingDistance = 35
local rKeyIsPressed = false
local placingStructure = false

for _, structureButton in pairs(StructureFrame:GetDescendants()) do
    if structureButton.ClassName == "ImageButton" then
        print("Works1")
        structureButton.MouseButton1Up:Connect(function()

            StructureFrame.Parent.Visible = false
            
            local yOrientation = 0
            local goodToPlace = false
            local placedStructure
            
            if placingStructure == false then
                placingStructure = true
                
                local clientStructure = Structures:FindFirstChild(structureButton.Name):Clone()
                clientStructure.BrickColor = BrickColor.new("Forest green")
                clientStructure.Material = "Neon"
                clientStructure.CanCollide = false
                clientStructure.Parent = game.Workspace 

Is this the line you’re erroring at? If so, are you certain you have a thing in your Structures folder with the name of the button?

Yes, I am certain that I have the thing in my structure folder with the name of the button.

I’d recommend you double check for certainty

Also, again, is that the line of error or do you have another Clone somewhere?

I manage to fixed it. Thanks tho!

1 Like