so my maze generator script make the position / size of the parts a bit weird and idk why can someone help me please?
i have added my script and images for help
My script:
local ignoreinstance = script.Parent
local TS = game:GetService("TweenService")
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local Part = script.Parent
local db = false
local TotalParts = #game.Workspace.Parts:GetChildren()
local CurrentParts = 0
function IsEven(num)
return num % 2 == 0
end
for i=5,1,-1 do
print("Starting In "..i)
wait(1)
end
print("Maze Generation Started")
local Finished = false
repeat
Elapsed = tick()
wait()
until Elapsed ~= nil
local Pos = {
Vector3.new(0,0,-15),
Vector3.new(-15,0,0),
Vector3.new(0,0,15),
Vector3.new(15,0,0)
}
local OldPositions = {}
while not Finished do
for i=1,4 do
script.Parent.Orientation = Vector3.new(0,i*90,0)
local ray = Ray.new(script.Parent.Position,Pos[i])
local part, position = workspace:FindPartOnRay(ray,ignoreinstance,false,true)
if part then
if not db then
db = true
if part.Name == "MazePart" and math.random(1,2) == 1 then
repeat
StartTick = math.round(tick())
wait()
until StartTick ~= nil
local PrevPartPosition = script.Parent.Position
script.Parent.Position = part.Position
local Distance = math.round((part.Position - PrevPartPosition).Magnitude)
local DistancePart = Instance.new("Part",game.Workspace)
DistancePart.Material = Enum.Material.SmoothPlastic
DistancePart.CanCollide = false
DistancePart.Anchored = true
local Orientation = Part.Orientation.Y
DistancePart.Orientation = Vector3.new(0,Orientation,0)
DistancePart.Size = Vector3.new(14,1,6)
if not IsEven(Distance) then
Distance = Distance +1
end -- Below this is where i set my parts position
if Orientation == -90 then
DistancePart.Position = PrevPartPosition+Vector3.new(1,0,(Distance/2))
elseif Orientation == 90 then
DistancePart.Position = PrevPartPosition-Vector3.new(-1,0,(Distance/2))
elseif Orientation == -180 then
DistancePart.Position = PrevPartPosition-Vector3.new((Distance/2),0,-1)
elseif Orientation == 0 then
DistancePart.Position = PrevPartPosition+Vector3.new((Distance/2),0,1)
end
DistancePart.Position = Vector3.new(math.round(DistancePart.Position.X),DistancePart.Position,math.round(DistancePart.Position.Z))
CurrentParts = CurrentParts + 1
PrevPartPosition = part.Position
table.insert(OldPositions,#OldPositions+1,part.Position)
part:Destroy()
end
if StartTick then
if math.round(tick() - StartTick) > 0.5 and CurrentParts < TotalParts then
print("No Parts Found")
script.Parent.Position = OldPositions[#OldPositions]
table.remove(OldPositions,#OldPositions)
StartTick = math.round(tick())
elseif CurrentParts == TotalParts and not Finished then
Finished = true
print("Maze Was Finished In "..math.round(tick() - Elapsed).." Seconds")
end
end
wait()
db = false
end
end
wait(0)
end
end
What i have with this script:
What i want: