for i, v in placedAttachmentArray do
if v.Position == hingePreview.Position and previousHinge ~= nil then
print("place hinge")
print("place rod")
return
elseif v.Position == hingePreview.Position then
print("place hinge")
return
end
end
for i, v in placedAttachmentArray do
if (v.Position-hingePreview.Position).Magnitude < 0.1 then -- Doing this so that if somehow the 2 positions are slightly different the code would still work.
print("place hinge")
if previousHinge ~= nil then
print("place rod")
end
return
end
end
for _, v in placedAttachmentArray do
if v.Position ~= hingePreview.Position then continue end
print("place hinge")
if not previousHinge then continue end
print("place rod")
return
end
These if statements are known as guard statements. Prints can be used in if statements, but in my preference, I use these to optimise my loops and functions.
Elseifs and nested ifs are sometimes slightly messy and with guard statements, it optimises the way you read it. Optimise is not always meant as boost performance.
You ideally really only use it in functions and loops. Not in that case where you only check one thing.
Oh and continue is only used in loops, that second code would error.