I’m making a system where there are randomly generated obby stages, and using bounding box, I add a part that reflects the stage’s size and place it on the stage.
However I’ve run into an issue. Sometimes the part doesn’t full stretch to the model’s actual size.
Correct:
As you can see on the red stage it perfectly covers the stage, however on the white a bit of the start and end are left out.
Is this because of the model? All of them have a primary part set to the first part of the stage but I don’t think that’s the reason.
Code:
local lastPart
repeat
local stage = stages:GetChildren()[math.random(1, #stages:GetChildren())]
local stagenew = stage:Clone()
table.insert(stages_added, stagenew)
stagenew.Parent = workspace.Checkpoints
if #stages_added == 1 then
stagenew:PivotTo(workspace.FirstPart.CFrame)
else
stagenew:PivotTo(lastPart:FindFirstChild("End").CFrame - Vector3.new(0,0, lastPart["End"].Size.Z))
end
-----------------
local cframe, size = stagenew:GetBoundingBox()
local tpPart = Instance.new("Part")
tpPart.Anchored = true
tpPart.CanCollide = false
tpPart.Size = size * Vector3.new(10,1,1)
tpPart.CFrame = cframe - Vector3.new(0,size.Y*1.2,0)
tpPart.Transparency = .4
tpPart.Parent = workspace.Teleporters
tpPart.Name = "Tp_Part"
game:GetService("CollectionService"):AddTag(tpPart, "CheckpointTP")
lastPart = stagenew
----------------- This is where the parts are made to match the stage.
local flagclone = flag:Clone()
flagclone.Parent = workspace.Checkpoints
flagclone:PivotTo(CFrame.new(stagenew.Start.Position) + Vector3.new(0,17,0))
flagclone.Name = "Checkpoint_".. #stages_added
task.wait()
until #stages_added == maxStages
Sorry, the code I showed is different from that of the pictures. The code that was used while those screenshots were taken was without modifying the cframe or size. The reason they are modified is to place them below each stage to teleport players to the checkpoint if they fall. So even if I were to not modify the bounding box it’d still not stretch fully
Okay so it sorta works but not really. Because all these stages have a primary part so when I get the pivot and place the part using it, it sorta goes in the middle of the stage.
So how can I get the boundingbox or the pivot without the primarypart interfering? The primary part is necessary, as I put the primarypart at the CFrame of the end of the previous stage
To connect it properly
Each stage has a start and an end part. The start part is the primarypart. When setting the cframe of a new stage, I put the cframe of the start part (Primary part), to match the cframe of the stage before it’s end part.