How to move a model?

Hi Other Developers,
I’ve been having some trouble with random obby generation.

Here is my script:

local GenerationID = 1
for _, Section: Model in RandomGenFolder:GetChildren() do
	Section:Clone()
	Section.Parent = game.Workspace:WaitForChild("Sections")
	Section.PrimaryPart = Section:FindFirstChild("endpoint")
	Section.Name = GenerationID
	if GenerationID > 1 then
		print("Ran")
		Section.PrimaryPart.CFrame = game.Workspace.Sections:FindFirstChild(tostring(GenerationID - 1)):FindFirstChild("startpoint").CFrame
	end
	GenerationID += 1
end

What this script is doing is getting the endpoint of a section of the obby and then setting the cframe to the startpoint of the section infront of it.

Thanks a lot!

1 Like
1 Like

Use this:

local GenerationID = 1
for _, Section: Model in RandomGenFolder:GetChildren() do
	Section:Clone()
	Section.Parent = game.Workspace:WaitForChild("Sections")
	Section.PrimaryPart = Section:FindFirstChild("endpoint")
	Section.Name = GenerationID
	if GenerationID > 1 then
		print("Ran")
		Section:SetPrimaryPartCFrame(game.Workspace.Sections:FindFirstChild(tostring(GenerationID - 1)):FindFirstChild("startpoint").CFrame)
	end
	GenerationID += 1
end

This uses the SetPrimaryPartCFrame method that moves all the other parts along with it. Do note however that it’s deprecated, and replaced with the :PivotTo() method. If you wanna implement that then you need to first put it somewhere in the workspace, get the distance (subtract last endpoint vector3 from primary part vector3)

Finally then, replace the line with this

Section:PivotTo(Section:GetPivot() * CFrame.new(distance))

May have messed up my geometry, so double check it, hopefully this helps! :smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.