You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
Im Making An Algorythm That Generates mazes
What is the issue?
It Works But Just Randomly Stops
What solutions have you tried so far?
I Tried Simplifying The Code And Even Rewritting some Bits
this is the code
while wait() do
--for t = 1,1000 do
for i,v in pairs(game.Workspace.Maze:GetChildren()) do
local attachment2 = v:FindFirstChild("Attachment")
local parts = game.ReplicatedStorage.MazeParts:GetChildren()
local order = math.random(1,3)
--for i,v in pairs(v:GetChildren()) do
--if v.Name == "Attachment" then
--print("Attachment")
--end
--end
if attachment2 ~= nil then
newpart = parts[order]:Clone()
v.Attachment.Orientation += Vector3.new(0,180,0)
local attachment2 = v.Attachment
local attachment1 = newpart.ConnectionAttachment
--Result1
local RayOrigin1 = attachment2.WorldPosition
local RayDirection1 = attachment1.WorldCFrame.LookVector
local Length = newpart.Size.Z
local resultZ = workspace:Raycast(RayOrigin1, RayDirection1 * Length)
local RayOrigin2 = attachment2.WorldPosition
local RayDirection2 = attachment1.WorldCFrame.LookVector
local Width = newpart.Size.X
local resultX = workspace:Raycast(RayOrigin1, RayDirection2 * Width)
if resultZ then
newpart:Destroy()
elseif resultX then
newpart:Destroy()
else
--Result2
newpart.Parent = game.Workspace.Maze
newpart.CFrame = attachment2.WorldCFrame * attachment1.CFrame:Inverse()
attachment2:Destroy()
--ammount = 0
wait(0.25)
end
end
end
end
Ah yes, You’re right. Put a Print statement in your loop to see if it stops printing when it stops working, then we can narrow the issue down. Also I assume there are no output errors?
So eventually, attachments of all of your parts are getting destroyed, and if statement starts returning false, thats why script stops doing anything.
To confirm this you can put a print statement directly under if attachment2 ~= nil, and see.
The issue is, you are destroying the attachment of original parts. Instead of it you need to destroy attachments of clones.
it doesn’t rlly mind if the attachment on original part is gone due to the attachment2 variable changing each time due to its ussing attachment2 to attach into attachment1