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

ReplicatedStorage.Chunk:395: attempt to index nil with 'Name'?

Asked by 3 years ago
Edited 3 years ago

Code:

local function addDiamond(chunk)
    local posGrid = chunk.positionGrid
    local instances = chunk.instances
    local chunkPosX = chunk.x
    local chunkPosZ = chunk.z

    for x = 0, X-1 do
        for z = 0, Z-1 do
            local pos = posGrid[x][z]

            if pos.Y >= MINDS and pos.Y <= MAXDS then

                math.randomseed(x * (chunkPosX+SEED) + z * (chunkPosZ+SEED))
                if math.random(1,5) == ROCK_DENSITY then
                    local cframe = CFrame.new(pos)
                        * CFrame.new(math.random() * math.random(-10, 10),0,math.random() * math.random(-10, 10))* CFrame.Angles(0, 2 * math.pi * math.random(), 0)

                    local rock = game.ReplicatedStorage.DiamonOre:Clone()
                    rock:SetPrimaryPartCFrame(cframe)
                    rock.Parent = workspace
                    local TouchingParts1 = rock.Rock1:GetTouchingParts()
                    local TouchingParts = rock.Rock:GetTouchingParts()
                    if TouchingParts.Parent.Name == "CopperOre" or  TouchingParts1.Parent.Name == "CopperOre" then  -- Here Is Where I Get Error
                        rock:Destroy()
                    end
                    local min = rock.Part.Position - (.5 * rock.Part.Size)
                    local max = rock.Part.Position + (.5 * rock.Part.Size)  
                    local region = Region3.new(min,max):ExpandToGrid(20)
                    local PartsInRegion = game.Workspace:FindPartsInRegion3(region,rock,math.huge)
                    local material = workspace.Terrain:ReadVoxels(region,4)[1][1][1] 
                    local Point = rock.Part
                    for _,Part in pairs(game.Workspace:FindPartsInRegion3(region,nil,math.huge)) do
                        if Part.Name == "TerrainPart" and not Stop then
                            Stop = true
                            rock:SetPrimaryPartCFrame(Part.CFrame)
                        end
                    end
                    if material == Enum.Material.Water then
                        rock:Destroy()
                    end
                    Stop = false
                    table.insert(instances, rock)
                end
            end
        end
    end
end 
0
remove the .Parents JesseSong 3916 — 3y
0
ok kidsteve923 139 — 3y
0
but if i do it wont work cuz i have many objects with the same name kidsteve923 139 — 3y
0
well nvm kidsteve923 139 — 3y
View all comments (2 more)
0
did it work? JesseSong 3916 — 3y
0
not really but i fixed it kidsteve923 139 — 3y

Answer this question