Having trouble moving a model

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
2 Likes

If you adjust its CFrame directly (model.PrimaryPart.CFrame), it’ll only move that individual part. In order to move the entire model with it, you need to call :SetPrimaryPartCFrame() on the model, instead.

Example:

-- The following line of code...
clone.PrimaryPart.CFrame = c1.CFrame
-- Becomes the following:
clone:SetPrimaryPartCFrame(c1.CFrame)
1 Like

That worked, thanks! I had no idea what the difference was between :SetPrimaryPartCFrame() and .CFrame! Thank you for your help!

1 Like