Problems with Cube Variants near other Cubes

I’m currently trying to make a game with custom variants of cubes and for the most part, it works pretty good, but I’m right now being spoonfeeded with problems. I don’t have all cube variants ready, but I’ll make them later. Here’s the problem that I’m having:

As you can see, some of the parts are a little wonky. Here’s how it’s supposed to look:

image

As you may have probably noticed, it’s only with 4 cubes. Here’s my code:

				local CFrameVectors = {
					upVector = CFrame.new(v.Position, v.Position + Vector3.new(0, 0.5, 0)).LookVector * 1.85,
					downVector = CFrame.new(v.Position, v.Position + Vector3.new(0, -0.5, 0)).LookVector * 1.85,
					rightVector = CFrame.new(v.Position, v.Position + Vector3.new(0.5, 0, 0)).LookVector * 1.85,
					leftVector = CFrame.new(v.Position, v.Position + Vector3.new(-0.5, 0, 0)).LookVector * 1.85,
					frontVector = CFrame.new(v.Position, v.Position + Vector3.new(0, 0, -0.5)).LookVector * 1.85,
					backVector = CFrame.new(v.Position, v.Position + Vector3.new(0, 0, 0.5)).LookVector * 1.85,
				}

				local params = RaycastParams.new()
				params.FilterType = Enum.RaycastFilterType.Exclude
				params.FilterDescendantsInstances = {v}

				local rayCast_UP = workspace:Raycast(v.Position, CFrameVectors.upVector, params)
				local rayCast_DOWN = workspace:Raycast(v.Position, CFrameVectors.downVector, params)
				local rayCast_RIGHT = workspace:Raycast(v.Position, CFrameVectors.rightVector, params)
				local rayCast_LEFT = workspace:Raycast(v.Position, CFrameVectors.leftVector, params)
				local rayCast_FRONT = workspace:Raycast(v.Position, CFrameVectors.frontVector, params)
				local rayCast_BACK = workspace:Raycast(v.Position, CFrameVectors.backVector, params)

				-- None --
				if not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 0, 0)

					v:Destroy()

					-- Up, Down --
				elseif rayCast_UP and not rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(90, 0, 0)

					v:Destroy()
				elseif not rayCast_UP and rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(-90, 0, 0)

					v:Destroy()
				elseif rayCast_UP and rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Double Sided Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 0, 90)

					v:Destroy()

					-- Left, Right --
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 90, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, -90, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and not rayCast_FRONT and rayCast_LEFT and rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Double Sided Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 0, 0)

					v:Destroy()

					-- Front, Back --
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 0, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Single Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 180, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and rayCast_BACK and rayCast_FRONT and not rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Double Sided Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 90, 0)

					v:Destroy()

					-- Front, Back, Left, Right --
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and rayCast_FRONT and not rayCast_LEFT and rayCast_RIGHT then
					print("gay :)")
					
					local New_Cube = Cubes:WaitForChild("Edge Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 0, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and not rayCast_BACK and rayCast_FRONT and rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Edge Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 90, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and rayCast_BACK and not rayCast_FRONT and not rayCast_LEFT and rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Edge Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, -90, 0)

					v:Destroy()
				elseif not rayCast_UP and not rayCast_DOWN and rayCast_BACK and not rayCast_FRONT and rayCast_LEFT and not rayCast_RIGHT then
					local New_Cube = Cubes:WaitForChild("Edge Beveled Cube"):Clone()
					New_Cube.Parent = workspace
					New_Cube.Name = v.Name
					New_Cube.Position = v.Position
					New_Cube.Orientation = Vector3.new(0, 180, 0)

					v:Destroy()
				end

(“v” is the part that I want to have a variant of (it’s in a for i, v loop))

Any help would be appreciated!

3 Likes