How do you make patterns

I’m trying to make a pattern that looks like this:


I made a loop to make parts in a direction, then I’m trying to offset 2 in a row then leave one.

My code so far makes this pattern:

When I run the script the loop adds 1 to a number each time and I check if its a multiple of 2 then offset the part I tried adding if it was a multiple of 3 but it didn’t work.

local start = script.Parent.Position
local ending = workspace.ending.Position
local direction = (ending-start).Unit

local Number = 0
local Offset = 0
local IsOffset = false

points = {}
table.insert(points,0,start)
while true do
	wait(1)
	game:GetService("RunService").Heartbeat:Wait()
	
	Number = Number + 1
	local pos = (6) * Number
	
	local Position = pos * -direction 
	local Cframe = CFrame.new(Position):ToObjectSpace(CFrame.new(start))
	table.insert(points,Number,Cframe.Position)
	
	Cframe = CFrame.new(Cframe.Position,ending)
	
	local Part = Instance.new("Part")
	Part.Anchored = true
	Part.Size = Vector3.new(1,1,1)
	Part.CFrame = Cframe
	Part.Parent = workspace
	Part.BrickColor = BrickColor.new("Lime green")
	
	
	if Number%2 == 0 then
		Offset = Offset + 1
		Cframe = Cframe * CFrame.new(-4, 0, 0)
			--[[local random = math.random(-80,-20)/10
			Cframe = Cframe * CFrame.new(0, random, 0)]]
		Part.Position = Cframe.Position
		Part.BrickColor = BrickColor.new("Really red")
	end
end
1 Like

I would just do it like this:

local Offsets = {
3,
-3,
0
}

for i = 1, 30 do -- 30 being the number of points you want.
    local Part = instance.new("part", game.Workspace)
    Part.Size = Vector3.new(1, 1, 1)
    Part.Position = Vector3.new(Offsets[(i%3) + 1], 1, 5 * i) -- X: Toggle between +3, -3, and 0 offset Y: Constant, Z: Move points forward by 5 for each new one.
end
3 Likes