#Obby Generator being weird

1 messages · Page 1 of 1 (latest)

fossil lark
#

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

#

(First game so im very slow)

#

Using the intregrated AI)

void basalt
#

what do you mean by

#

spawn incorrectly?

#

@fossil lark

fossil lark
#

Like sideways its strange

#

Should spawn like this

void basalt
#

Sideways?

fossil lark
#

However

#

its 90 degrees

#

Like this

void basalt
#
local newPivot = CFrame.new(orientation.Position) * CFrame.Angles(0, 0, 0)
#

See this line in your script?

#
CFrame.Angles(0, 0, 0)
fossil lark
#

Yup

void basalt
#

you could try 90, 180 for each one there

#

example

#
CFrame.Angles(math.rad(90), 0, 0)
#

or

#
CFrame.Angles(math.rad(180), 0, 0)
#

or

#
CFrame.Angles(0, math.rad(180), 0)
#

just try randomly, you'll find out which one is the correct one.

fossil lark
#

Alright thanks

hazy radishBOT
#

studio** You are now Level 1! **studio