Increasing and decreasing NPC Size with TweenService

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A server script to increase the size of an NPC by 4x and then reduce it back to original size.

  1. What is the issue? Include screenshots / videos if possible!

The code works great on players in the game, but for NPC Models the enlarged model sinks halfway into the ground.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked through many posts. It appears there needs to be some adjustment to the position but I haven’t had any success moving the model’s cframe either before the tween - it ends up being a sequence where the model is moved upwards and then enlarged. I would like it to be a smooth enlargement with the NPC’s feet remaining on the ground.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The code below is in a server script contained in the NPC model.

local char = script.Parent
local humanoid = char.Humanoid
local hrp = char.HumanoidRootPart
local TweenService = game:GetService("TweenService")
local humanoid = script.Parent.Humanoid -- replace 'NPC' with the name of your NPC model

local TweenService = game:GetService("TweenService")
TweenService:Create(humanoid.HeadScale, TweenInfo.new(1), {Value = 4}):Play()
TweenService:Create(humanoid.BodyDepthScale, TweenInfo.new(1), {Value = 4}):Play()
TweenService:Create(humanoid.BodyWidthScale, TweenInfo.new(1), {Value = 4}):Play()
TweenService:Create(humanoid.BodyHeightScale, TweenInfo.new(1), {Value = 4}):Play()

wait(5)	

TweenService:Create(humanoid.HeadScale, TweenInfo.new(1), {Value = 1}):Play()
TweenService:Create(humanoid.BodyDepthScale, TweenInfo.new(1), {Value = 1}):Play()
TweenService:Create(humanoid.BodyWidthScale, TweenInfo.new(1), {Value = 1}):Play()
TweenService:Create(humanoid.BodyHeightScale, TweenInfo.new(1), {Value = 1}):Play()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Will this be any help for you?
Took me 10-20 minutes to type/test…

local tweenService = game:GetService("TweenService")

local function ChangeSizeFunction(character, changeSizeTable)
	local humanoid = character:WaitForChild("Humanoid")
	if humanoid then
		if not humanoid:FindFirstChild("BodyHeightScale") then
			local bodyHeightScale = Instance.new("NumberValue")
			bodyHeightScale.Name = "BodyHeightScale"
			bodyHeightScale.Parent = humanoid
			bodyHeightScale.Value = 1
			tweenService:Create(bodyHeightScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.height}):Play()
		else
			tweenService:Create(humanoid.BodyHeightScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.height}):Play()
		end
		if not humanoid:FindFirstChild("BodyWidthScale") then
			local bodyWidthScale = Instance.new("NumberValue")
			bodyWidthScale.Name = "BodyWidthScale"
			bodyWidthScale.Parent = humanoid
			bodyWidthScale.Value = 1
			tweenService:Create(bodyWidthScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.width}):Play()
		else
			tweenService:Create(humanoid.BodyWidthScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.width}):Play()
		end
		if not humanoid:FindFirstChild("BodyDepthScale") then
			local bodyDepthScale = Instance.new("NumberValue")
			bodyDepthScale.Name = "BodyDepthScale"
			bodyDepthScale.Parent = humanoid
			bodyDepthScale.Value = 1
			tweenService:Create(bodyDepthScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.depth}):Play()
		else
			tweenService:Create(humanoid.BodyDepthScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.depth}):Play()
		end
		if not humanoid:FindFirstChild("HeadScale") then
			local headScale = Instance.new("NumberValue")
			headScale.Name = "HeadScale"
			headScale.Parent = humanoid
			headScale.Value = 1
			tweenService:Create(headScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.headSize}):Play()
		else
			tweenService:Create(humanoid.HeadScale, changeSizeTable.tweenInformation, {Value = changeSizeTable.headSize}):Play()
		end
	end
end

local character = script.Parent

local changeSizeTable = 
{
	tweenInformation = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
	height = 4, width = 4, depth = 4, headSize = 4,
}
local changeSizeTable2 = 
{
	tweenInformation = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In),
	height = 1, width = 1, depth = 1, headSize = 1,
}

ChangeSizeFunction(character, changeSizeTable)
wait(5)
ChangeSizeFunction(character, changeSizeTable2)
1 Like