How would you efficiently detect if this puzzle is completed

  1. 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

  2. the puzzle works by rotating the parts to complete a line

  3. I’ve tried rescripting but kept running into messy lines of code that bugged out quite frequently

All responses are honored! thank you!

1 Like

ignore it not being centered I’m going to fix later

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:

image

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

1 Like

Hi, Thank you for your quick reply :slight_smile: !
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)

1 Like

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.

Hi again! sorry if i seem annoying but i still dont understand how this would work! maybe try explaining it simpler.

these are the AbsolutePositions of 2 lined up Ui Elements

I will make a quick video visualizing what i am trying to say, give me a few minutes

Alright! tysm! ill be awaiting your reply
:smiley:

This might be a bit loud and sorry for the bad audio quality, Hope it helps:

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

1 Like

thank you! I will try to contact u if I need any help!

image

1 Like

You’re welcome, just make sure the anchor point is set to 0.5,0 and the position to 1 and -1 for the outlet