Need help with putting part position at end of random-generated obby

So I’m trying to make a round game where different parts of an obby is stitched together to make one big obby. The thing is there is no finish part. I have a placeholder part where I want it to go at the end of the random-generated obby. I have no idea how to do it.

local runservice = game:GetService("RunService")
local players = game:GetService("Players")
local workspace = game.Workspace
local replicatedStorage = game:GetService("ReplicatedStorage")
local random = Random.new(replicatedStorage.Seed.Value)
local finish = workspace.FINISH

local models = {}

local part = workspace.Start
local children = workspace.Models:GetChildren()
table.sort(children, function(a, b) return a.Name < b.Name end)

for i, child in children do
	local chance = child:GetAttribute("Chance") or 1
	for i = 1, chance do table.insert(models, child) end
end

for count = 0, 15, 1 do
	local model = models[random:NextInteger(1, #models)]:Clone()
	model:PivotTo(part.CFrame)
	model.Parent = workspace

	part = model.End
	task.wait(0)
end

Thanks!

Hi there. Forgive me if I’m oversimplifying it. But wouldn’t you just build a “last part of obby” model then place it inside a folder or serverstorage, clone it then parent it to the workspace + proper positioning to how you need it?

This might help.

for count = 0, 15, 1 do
	local model = models[random:NextInteger(1, #models)]:Clone()
	model:PivotTo(part.CFrame)
	model.Parent = workspace

	part = model.End
    if count == 15 then
        --this must be the last part
        --add another end part or something
    end
	task.wait()
end

im bad at scripting lol so idk how to do the proper positioning part

i changed some part of the code to this and it worked!

local runservice = game:GetService("RunService")
local players = game:GetService("Players")
local workspace = game.Workspace
local replicatedStorage = game:GetService("ReplicatedStorage")
local random = Random.new(replicatedStorage.Seed.Value)

local models = {}

local part = workspace.Start
local children = workspace.Models:GetChildren()

task.wait(1)

table.sort(children, function(a, b) return a.Name < b.Name end)

for i, child in children do
	local chance = child:GetAttribute("Chance") or 1
	for i = 1, chance do table.insert(models, child) end
end

for count = 0,15,1 do
	local model = models[random:NextInteger(1, #models)]:Clone()
	model:PivotTo(part.CFrame)
	model.Parent = workspace

	part = model.End
	
	local finish = workspace.FINISH
	
	if count == 15 then
		finish.Position = model.End.Position
	end
	
	task.wait(0)
end

thanks!