Why does my code not return the proper size of a model?

I’m testing out making a random tile generation system, but when I try to offset tiles via getting the size of the previous tile, it doesn’t move them correctly.


The highlight tile is 100 studs, and so the straight line tile should have been offset by 100 studs, yet was only offset by 26

local function buildPrefab(CF: CFrame, Name: string?, Chain: number?)
	Name = Name or next(Favorites)
	Chain = Chain and Chain + 1 or 1
	
	local Prefab = Prefabs:FindFirstChild(Name):Clone() :: Model
	Prefab:PivotTo(CF)
	Prefab.Parent = workspace
	if Chain == MaxChain then return end
	
	local FavoritePrefabs = Favorites[Name]
	local ChosenPrefab = FavoritePrefabs[math.random(1, #FavoritePrefabs)] :: Model
	local ChosenSize = ChosenPrefab:GetExtentsSize()
	local NewCF = CF * CFrame.new(ChosenSize.X + math.random(1, 5), 0, 0)
	
	buildPrefab(NewCF, ChosenPrefab.Name, Chain)
end

task.defer(buildPrefab, CFrame.new(0, 0, 0))

The extents size is relative to the primary part CFrame, so maybe check if your primary part is oriented correctly. Based on what I can see in the code, it’s possible you are just getting the size from the wrong axis for a given model, maybe because the primary part isn’t rotated the right way. Then, you are adding a random value between 1 and 5, which might be the reason you got 26.

25 (the wrong axis size maybe?) and then plus 1 (your random number?)

That’s my guess.

the main problem is I was indeed getting the size of the wrong model on accident

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.