I am Making a game where you will have to solve puzzles to open doors I’ve made the puzzle and I’m decent at scripting, although I realized my scripts were not efficient and they bugged out frequently
the puzzle works by rotating the parts to complete a line
What i would suggest here is have UI elements (OR YOU COULD USE X,Y COORDINATES INSTEAD OF UI ELEMENTS) at the border of each part and have them rotate relative to the part like so:
you want to iterate through each part, say the part has 2 outlets (2 red lines as provided in the screenshot)
you will go through every other outlet (which are UI elements in this case) and check if the absolutepositions match up, then you will add the 2 UI elements to a ‘completedcheck’ table, if all the UI elements are in that ‘completedcheck’ table then that means the puzzle has been solved.
The check above should be run at every move the player makes, so it has to be well optimized.
I know it’s very confusing but ask questions if you need and I will try answer
Hi, Thank you for your quick reply !
I do not understand yet what you mean with UI elements Could you maybe link an Api-reference i couldn’t seem to find one (example. GuiObject | Documentation - Roblox Creator Hub)
By UI elements i mean any UI element, a frame, a textbox, anything with an ‘absoluteposition’ property. You will need to compare the absoluteposition property of all the outlets marked red in the image, if the outlets’ absoluteposition are equal at two parts, that means they’re lined up.
You don’t have to use a UI element either, you can just work with numbers directly.
Wow! that’s smart! would you advise checking every time from the element itself or Checking from 1 script that handles all! again tysm! after the reply ill check it as the solution
I’d advise checking from 1 script, do it like this:
local CheckComplete = {}
for i, v in pairs(partsOutlet) do
local AbsP1 = v.AbsolutePosition
for n, k in pairs(partsOutlet) do
if not v == k then
if AbsP1 = k.AbsolutePosition then
table.insert(CheckComplete, v)
table.insert(CheckComplete, k)
-- DON'T FORGET TO REMOVE K AND V FROM THE PARTSOUTLET TABLE
end
end
end
end
if #CheckComplete == #partsOutlet then
-- the puzzle is solved.
end
There is probably a more effective way to write this but this should do for now, best of luck