Obby Sequence System Not Setting Positions Correctly

Hey guys. I am currently making an Obby System that randomly selects levels for it. I want it to properly order them with correct positioning. For some reason, the CFrame of the levels will not be positioned correctly and will overlap the original CFrame of the level in ReplicatedStorage instead (Basically not moved at all). Nothing errors, and I tried to print different parts of my script, but everything prints out as expected, except the CFrames of course.

Here is how the system works:
The green “start” part overlaps the previous level’s red “end” part.
And yes, the “start” part is the PrimaryPart of each of the level’s model. (Each level is a model.)
Representation of a level:

Explorer:

OrderingScript:

--This Script Orders the Levels into a Sequence that Creates the Obby

--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Variables
local totalLevelCount = 10

local levelsStorage = ReplicatedStorage:WaitForChild("Levels"):GetChildren()
local currentLevelsFolder = game.Workspace:WaitForChild("CurrentLevels")

local lobby = game.Workspace:WaitForChild("Lobby"):WaitForChild("Lobby")
local lobbyCFrame = lobby:WaitForChild("End").CFrame


--Creating Level Sequence
for level = 0, totalLevelCount - 1, 1 do
	print("Loop Started")
	local newLevel = levelsStorage[math.random(1, #levelsStorage)]:Clone()
	print(newLevel.Name)
	newLevelCFrame = newLevel:WaitForChild("Start").CFrame
	
	--If first level then it starts in front of the lobby
	if #currentLevelsFolder:GetChildren() == 0 then
		print("Loading First Level")
		
		local lastLevel = Instance.new("BoolValue")
		lastLevel.Name = "lastLevel"
		lastLevel.Value = true
		lastLevel.Parent = newLevel
		
		newLevel.Parent = currentLevelsFolder
		newLevelCFrame = lobbyCFrame
		
		
		print(newLevelCFrame)
		
	else
		
		print("level other than first level")
		
		for i, v in pairs(currentLevelsFolder:GetChildren()) do
			--v is the latest level with the lastLevel value
			if v:FindFirstChild("lastLevel") then
				print("Loading Next Level")
				
				newLevel.Parent = currentLevelsFolder
				newLevelCFrame = v:WaitForChild("End").CFrame
				v:WaitForChild("lastLevel").Parent = newLevel
				
				
				print(newLevelCFrame)
				
			end
		end
		
	end
	
	
	
	
end

Output:

Loop Started
Jump1
Loading First Level
-33, 3.5, 0, -4.37113883e-08, 0, 1, 0, 0.99999994, 0, -1, 0, -4.37113883e-08
Loop Started
Platform2
level other than first level
Loading Next Level
-53, 4.5, -153.5, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform2
level other than first level
Loading Next Level
-53, 4.5, -125.5, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform2
level other than first level
Loading Next Level
-53, 4.5, -125.5, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform1
level other than first level
Loading Next Level
-53, 4.5, -125.5, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform1
level other than first level
Loading Next Level
-53.125, 4.5, -99.25, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform1
level other than first level
Loading Next Level
-53.125, 4.5, -99.25, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform1
level other than first level
Loading Next Level
-53.125, 4.5, -99.25, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Jump1
level other than first level
Loading Next Level
-53.125, 4.5, -99.25, 1, 0, 0, 0, 1, 0, 0, 0, 1
Loop Started
Platform2
level other than first level
Loading Next Level
-53, 4.5, -153.5, 1, 0, 0, 0, 1, 0, 0, 0, 1

Thank you all

1 Like

So you just want a way to move and face the player a certain direction …
This might do the trick for ya.

function movePlayerToPad(ply, pad, rot)
    local root = ply.Character:WaitForChild("HumanoidRootPart")
    ply.Character:MoveTo(pad.CFrame.p + Vector3.new(0, 3, 0))
    root:SetPrimaryPartCFrame(CFrame.new(root.Position) * CFrame.Angles(0, math.rad(rot), 0))
end

I’m not trying to position the player, I’m trying to position the actual levels using the sequence system.

Hmm, pretty hard without being able to test anything.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local totalLevelCount = 10
local levelsStorage = ReplicatedStorage:WaitForChild("Levels"):GetChildren()
local currentLevelsFolder = game.Workspace:WaitForChild("CurrentLevels")
local lobby = game.Workspace:WaitForChild("Lobby"):WaitForChild("Lobby")
local lobbyCFrame = lobby:WaitForChild("End").CFrame

for level = 0, totalLevelCount - 1 do
    local newLevel = levelsStorage[math.random(1, #levelsStorage)]:Clone()
    local newLevelCFrame

    if #currentLevelsFolder:GetChildren() == 0 then
        local lastLevel = Instance.new("BoolValue")
        lastLevel.Name = "lastLevel"
        lastLevel.Value = true
        lastLevel.Parent = newLevel
        newLevel.Parent = currentLevelsFolder
        newLevelCFrame = lobbyCFrame
    else
        for _, v in pairs(currentLevelsFolder:GetChildren()) do
            if v:FindFirstChild("lastLevel") then
                newLevel.Parent = currentLevelsFolder
                newLevelCFrame = v:WaitForChild("End").CFrame * CFrame.new(Vector3.new(0, 0, -v.PrimaryPart.Size.Z))
                v:WaitForChild("lastLevel").Parent = newLevel
            end
        end
    end
end

Adjust the transformation part (CFrame.new(Vector3.new(0, 0, -v.PrimaryPart.Size.Z)))
Based on the actual dimensions and structure of your levels.

This looks right, but again without testing it’s just a guess. GL!

Alright, I got the code to work. It wasn’t the same solution you had but thank you anyway.

1 Like

Great, I think I may have been a bit out there with that one … :joy: