-
What do you want to achieve? I want to make an Infinite Obby.
-
What is the issue? Stages are Positioning not the right Way
-
What solutions have you tried so far? I looked on the DevForum for any Solution but found nothing. After that, I tried ChatGPT but It didn’t take many seconds to find out that it was a dumb idea.
Here is the Code I’m using:
local Stages = game:GetService("ServerStorage"):WaitForChild("Stages")
local CheckPoint = game:GetService("ServerStorage"):WaitForChild("CheckPoint")
local CheckPointsFolder = workspace:WaitForChild("CheckPoints")
local StagesFolder = workspace:WaitForChild("Stages")
local maxStages = 10
-- Function to deep clone a model
local function deepCloneModel(original, cloneParent)
local clone = original:Clone()
clone.Parent = cloneParent
for _, child in ipairs(original:GetChildren()) do
if child:IsA("BasePart") then
local childClone = child:Clone()
childClone.Parent = clone
end
end
return clone
end
local previousCheckpoint = nil
local firstCheckpoint = true
for i = 1, maxStages do
print(i)
local allStages = Stages:GetChildren()
local chosenStage = allStages[math.random(1, #allStages)]:Clone()
local cCheckPoint = deepCloneModel(CheckPoint, CheckPointsFolder)
if chosenStage and cCheckPoint then
if not firstCheckpoint then
cCheckPoint:SetPrimaryPartCFrame(previousCheckpoint:GetPrimaryPartCFrame())
else
firstCheckpoint = false
end
cCheckPoint.SpawnLocation.Name = tostring(i)
cCheckPoint.Name = "CheckPoint" .. i
local chosenStageEnd = chosenStage:FindFirstChild("End")
if chosenStageEnd then
cCheckPoint.PrimaryPart.Position = chosenStageEnd.Position
else
print("End not found in Stage", i)
chosenStage:Destroy()
continue
end
chosenStage.Name = "Stage" .. i
chosenStage.Parent = StagesFolder
previousCheckpoint = cCheckPoint
else
print("Stage or CheckPoint not found")
end
end
Any help would be appreciated!