BoundingBox not getting full Model size

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:
image

Incorrect:

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

Any help appreciated!

1 Like

I’m guessing it’s becuse you’re modifying the returned size and CFrame, when you shouldn’t.

Code:

local lastPart = nil

repeat 
	local stage = stages:GetChildren()[math.random(#stages:GetChildren())]
	
	-- Create stage
	local stagenew = stage:Clone()
	stagenew.Parent = workspace.Checkpoints
	
	table.insert(stages_added, stagenew)

	if lastPart then
		stagenew:PivotTo(lastPart.End.CFrame - Vector3.new(0,0, lastPart.End.Size.Z))
	else
		stagenew:PivotTo(workspace.FirstPart.CFrame)
	end
	
	lastPart = stagenew
	
	-- Create bounding box
	local cframe, size = stagenew:GetBoundingBox()
	
	local tpPart = Instance.new("Part")
	tpPart.Anchored = true
	tpPart.CanCollide = false
	tpPart.Size = size
	tpPart.CFrame = cframe
	tpPart.Transparency = .4
	tpPart.Name = "Tp_Part"
	tpPart.Parent = workspace.Teleporters
	
	game:GetService("CollectionService"):AddTag(tpPart, "CheckpointTP")
	
	-- Create flag
	local flagclone = flag:Clone()
	flagclone.Name = "Checkpoint_".. #stages_added
	flagclone:PivotTo(CFrame.new(stagenew.Start.Position) + Vector3.new(0,17,0))
	flagclone.Parent = workspace.Checkpoints

	task.wait()
until #stages_added == maxStages

I’ve also moved some parts around in your code for readability.

1 Like

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

Could you use the code and send a screenshot of what it looks like?

The one with the modified bounding box or the one unmodified?

The unmodified one, which is the code I sent.

if you want to get the size of a model you should use

model:GetExtentsSize()

which returns the exact size of the model.

You can then position it by getting the position of the model with

model:GetPivot().Position

which returns the exact position of the model.

bounding box in ohio be like


There’s still a gap in the bounding box

1 Like

what about getting the cframe of the stage, do I use :GetPivot()?
Nevermind, Didn’t see your edit

yes :GetPivot() gives you the CFrame, :GetPivot.Position is the Vector3

Oh, we can try using :GetExtentsSize as KrimsonWolf said then, it is less performant though since it’s more accurate.

Code:

local lastPart = nil

repeat 
	local stage = stages:GetChildren()[math.random(#stages:GetChildren())]

	-- Create stage
	local stagenew = stage:Clone()
	stagenew.Parent = workspace.Checkpoints

	table.insert(stages_added, stagenew)

	if lastPart then
		stagenew:PivotTo(lastPart.End.CFrame - Vector3.new(0,0, lastPart.End.Size.Z))
	else
		stagenew:PivotTo(workspace.FirstPart.CFrame)
	end

	lastPart = stagenew

	-- Create bounding box
	local size = stagenew:GetExtentsSize()

	local tpPart = Instance.new("Part")
	tpPart.Anchored = true
	tpPart.CanCollide = false
	tpPart.Size = size
	tpPart.CFrame = stagenew.PrimaryPart.CFrame
	tpPart.Transparency = .4
	tpPart.Name = "Tp_Part"
	tpPart.Parent = workspace.Teleporters

	game:GetService("CollectionService"):AddTag(tpPart, "CheckpointTP")

	-- Create flag
	local flagclone = flag:Clone()
	flagclone.Name = "Checkpoint_".. #stages_added
	flagclone:PivotTo(CFrame.new(stagenew.Start.Position) + Vector3.new(0,17,0))
	flagclone.Parent = workspace.Checkpoints

	task.wait()
until #stages_added == maxStages

Edit: Found out the reason :GetBoundingBox wasn’t working, it’s relative to the PrimaryPart if one was set:

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 I’d need to figure out how to get the cframe without the primary part interfering

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

Is your PrimaryPart exactly level with the ground? Or is it higher/lower? A screenshot of your PrimaryPart would help.

I also want to know, is the part size correct?


The primary parts are the start of each stage
There is no ground for it to be level with though

Make a single model that contains all of those other models and give that single model a new primary part or none at all I am pretty sure

is there a reason why you have it set to there? why not just make a spawn brick?

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.

Just offset the part with half the X/Z size of it.

Code:

local lastPart = nil

repeat 
	local stage = stages:GetChildren()[math.random(#stages:GetChildren())]

	-- Create stage
	local stagenew = stage:Clone()
	stagenew.Parent = workspace.Checkpoints

	table.insert(stages_added, stagenew)

	if lastPart then
		stagenew:PivotTo(lastPart.End.CFrame - Vector3.new(0,0, lastPart.End.Size.Z))
	else
		stagenew:PivotTo(workspace.FirstPart.CFrame)
	end

	lastPart = stagenew

	-- Create bounding box
	local size = stagenew:GetExtentsSize()

	local tpPart = Instance.new("Part")
	tpPart.Anchored = true
	tpPart.CanCollide = false
	tpPart.Size = size
	tpPart.CFrame = stagenew.PrimaryPart.CFrame + Vector3.new(0, size.Y / 2, size.Z / 2)
	tpPart.Transparency = .4
	tpPart.Name = "Tp_Part"
	tpPart.Parent = workspace.Teleporters

	game:GetService("CollectionService"):AddTag(tpPart, "CheckpointTP")

	-- Create flag
	local flagclone = flag:Clone()
	flagclone.Name = "Checkpoint_".. #stages_added
	flagclone:PivotTo(CFrame.new(stagenew.Start.Position) + Vector3.new(0,17,0))
	flagclone.Parent = workspace.Checkpoints

	task.wait()
until #stages_added == maxStages

I did size.Z / 2 here but it depends on your orientation. If it doesn’t work, get rid of the size.Z part and make the X position size.X / 2.