I am trying to recreate a game like Corridor Of Hell as a side project, but my main script to move the stages (which are grouped objects) after randomizing them isn’t working. The script moves the center of the stage (the PrimaryPart), but not the other parts. Am I doing something wrong?
Script:
--< Storage
local serverStorage = game:GetService("ServerStorage")
local stageFolder = serverStorage.Stages
local corridorFolder = workspace.Corridor
--< Centers
local centersfolder = workspace.Centers
local c1 = centersfolder.Stage1Center
local c2 = centersfolder.Stage2Center
local c3 = centersfolder.Stage3Center
local c4 = centersfolder.Stage4Center
local c5 = centersfolder.Stage5Center
local c6 = centersfolder.Stage6Center
local c7 = centersfolder.Stage7Center
local function pickStage1()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c1.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage2()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c2.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage3()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c3.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage4()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c4.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage5()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c5.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage6()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c6.CFrame
clone.Parent = corridorFolder
end
end
local function pickStage7()
local choice = math.random(1,#stageFolder:GetChildren())
if stageFolder:FindFirstChild(choice) then
local clone = stageFolder:FindFirstChild(choice):Clone()
clone.PrimaryPart.CFrame = c7.CFrame
clone.Parent = corridorFolder
end
end
local function generateStages()
pickStage1()
pickStage2()
pickStage3()
pickStage4()
pickStage5()
pickStage6()
pickStage7()
end
while true do
generateStages()
repeat wait() until game:GetService("ReplicatedStorage").TimerData.TotalTimeLeft.Value <= 0
end