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