How do I resize a model with a script

I’ve been trying to resize a model with a script but every time I run my script every thing resizes unevenly
any advise would be helpful.

3 Likes

This function should work good. Just call the function with the model and the size.

local function ScaleModel(model, scale)
	
	local primary = model.PrimaryPart
	local primaryCf = primary.CFrame
	
	for _,v in pairs(model:GetDescendants()) do
		if (v:IsA("BasePart")) then
			v.Size = (v.Size * scale)
			if (v ~= primary) then
				v.CFrame = (primaryCf + (primaryCf:inverse() * v.Position * scale))
			end
		end
	end
	
	return model
	
end


--sample how to call the function
local carmodel = game.Workspace.Car
ScaleModel(carmodel, 10) --makes it 10 times larger
31 Likes

for anyone having trouble with the code (a rotation problem) just modify this line
v.CFrame = (primaryCf + (primaryCf:inverse() * v.Position * scale))
to:
v.CFrame = (primaryCf + (primaryCf:inverse() * v.Position * scale)) * v.CFrame.Rotation

(and yes ik that this reply is late but for anyone wondering yeah there u go)

3 Likes

is it possible to do this over time?

Just thought I should mention that you no longer need to write a custom function to scale models. I thought there wasn’t a method for it until I did some research.

Simply use the ScaleTo method.

3 Likes