Trying to make an infinitely generating obby but half my obby parts spawn incorrectly, anyone able to help i can vc
Heres the code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local obbyPartsFolder = ReplicatedStorage.ObbyParts
local generatedObby = Workspace.GeneratedObby
local TIME_BETWEEN_PARTS = 10 -- seconds
local MAX_PARTS = 100
local partCount = 0
while partCount < MAX_PARTS do
partCount = partCount + 1
local partTemplates = obbyPartsFolder:GetChildren()
if #partTemplates == 0 then
warn("No templates found in ObbyParts!")
break
end
local template = partTemplates[math.random(1, #partTemplates)]
local newPart = template:Clone()
-- Calculate the position for this part: always along global Z+ axis
local position = Vector3.new(0, 0, 35 * (partCount - 1))
-- Always face forward (no rotation)
local orientation = CFrame.new(position, position + Vector3.new(0, 0, 1))
if newPart:IsA("BasePart") then
newPart.CFrame = orientation
elseif newPart:IsA("Model") then
-- Move model so its pivot is at the correct position and orientation
local pivot = newPart:GetPivot()
local offset = orientation.Position - pivot.Position
-- Set orientation to face forward (no rotation)
local newPivot = CFrame.new(orientation.Position) * CFrame.Angles(0, 0, 0)
newPart:PivotTo(newPivot)
else
warn("Template is not a BasePart or Model: " .. newPart.Name)
newPart:Destroy()
continue
end
newPart.Parent = generatedObby
task.wait(TIME_BETWEEN_PARTS)
end
** You are now Level 1! **