Help with Obby CFrame

I am creating a new game where there is an obby tower and it is randomly generated from a library of obby segments. The goal is to reach the top of the tower first.

Since the tower goes around in spirals, the segments can only align with the gaps that aren’t rotated. There is a photo below showing this in action. I turned the second part to show that I can rotate the segments correctly with my script but I can’t move them toward the right spot as you can see on line 4 of the script.

I have tried searching for solutions based on which way the checkpoint is facing but I couldn’t find anything that I can implement into my own script that I could understand.

Script: (The i value is at 10 because I only have 10 checkpoints so far)

for i = 10, 1, -1 do
		local newObstacle = repStorage.Segments[math.random(1,2)]:Clone()
		newObstacle:SetPrimaryPartCFrame(CFrame.Angles(checkpoints[i].Orientation.X, 0, 0))
		newObstacle:SetPrimaryPartCFrame(checkpoints[i].CFrame +, 0, 0))
		newObstacle.Parent = workspace.Obstacles


Consider giving each possible segment an extra part which serves as a reference for where it should meet up with the previous checkpoint. That way you just need to move everything so that the reference part has the exact same position and orientation as the checkpoint. You can remove this reference part after loading the segment.

newObstacle:SetPrimaryPartCFrame(checkpoints[i].CFrame +, 0, 0))

The (30, 0, 0) offset you’re adding is relative to the world’s rotation, not the checkpoint’s rotation. That’s why your second segment appears to get pushed the same way the first segment was. You can replace it with this:

newObstacle:SetPrimaryPartCFrame(checkpoints[i].CFrame:PointToWorldSpace(, 0, 0)))

The way the segment is offset will now depend on the rotation of the checkpoint.

Where are you setting the PrimaryPart of your segment models? Try putting a large Part that is Transparent and CanCollide false in each segment model then make it the model PrimaryPart.
That way you can fine tune the Parts inside each model so they all align correctly.

1 Like

Yes, do this as its what I meant in my first reply.

1 Like

I do have a large PrimaryPart hence why I used SetPrimaryPartCFrame but reading this comment sparked my brain for a better idea. Instead of basing the position and rotation off the checkpoints, I can just put more invisible bricks where the segments should be between each checkpoint. So that is exactly what I did and it works perfectly.

I will give you the solution because it is what sparked that idea. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.