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 

6 comments

0

remove the .Parents

0

ok

0

but if i do it wont work cuz i have many objects with the same name

0

well nvm

0

did it work?

0

not really but i fixed it