Shrinking the player slowly instead of instantly doing so

Hi, whenever a player touches a block, they shrink. How do I dlowly shrink the player instead of an instant one? Here is my working code:

local Touch
local RoundModule = require(script.RoundModule)
Touch = script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (Player)  then
		local NPS = Player:FindFirstChild("NormalPlayerSize")
		local P = Player:FindFirstChild("Piggy")
		if (NPS) and (not P) then
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			if Humanoid then
				local HD = Humanoid:GetAppliedDescription()
				HD.HeadScale = HD.HeadScale * .4
				HD.DepthScale = HD.DepthScale * .4
				HD.WidthScale = HD.WidthScale * .4
				HD.HeightScale = HD.HeightScale * .4
				Humanoid:ApplyDescription(HD)
			end	
			NPS:Destroy()
			RoundModule.InsertTag(Player, "SmallPlayer")
		end
	end

end)
1 Like

You should use a for i = loop. Seeing as how the player’s size is reduced by .4, you should use for i = 1,4 and HD.HeadScale = HD.HeadScale * i/10. Put all 4 scale lines of code into a for loop all using the same formula. If you multiply the second number of the for i = loop (e.x. i = 1,8/1,16), and you multiply the 10 by the same multiple (e.x. i/20 or i/40), it would give a smoother effect. Remember to use a wait()

Can you provide an example? 30

Alright, I whipped one up but the .4 at the beginning is underlined, how would i fix this?

for i, .4, .1 do
					local HD = Humanoid:GetAppliedDescription()
					HD.HeadScale = HD.HeadScale * i
					HD.DepthScale = HD.DepthScale * i
					HD.WidthScale = HD.WidthScale * i
					HD.HeightScale = HD.HeightScale * i
					Humanoid:ApplyDescription(HD)
				end

You could try using TweenService for that.

Here’s the current script, the player shrunk too small. Would you know how to fix this?

local Touch
local RoundModule = require(script.RoundModule)
Touch = script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (Player)  then
		local NPS = Player:FindFirstChild("NormalPlayerSize")
		local P = Player:FindFirstChild("Piggy")
		if (NPS) and (not P) then
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			if Humanoid then
				for i = 1, 4, 1 do
					local HD = Humanoid:GetAppliedDescription()
					HD.HeadScale = HD.HeadScale * i/10
					HD.DepthScale = HD.DepthScale * i/10
					HD.WidthScale = HD.WidthScale * i/10
					HD.HeightScale = HD.HeightScale * i/10
					Humanoid:ApplyDescription(HD)
					wait(.2)
				end

			end	
			NPS:Destroy()
			RoundModule.InsertTag(Player, "SmallPlayer")
		end
	end

end)

It’s because you’re using the current Scales when you multiply.

Save a variable referencing the old values.

local HeadScale = HD.HeadScale
local DepthScale = HD.DepthScale
local WidthScale = HD.WidthScale
local HeightScale = HD.HeightScale

for i = 1, 4 do
    local HD = Humanoid:GetAppliedDescription()

    HD.HeadScale = HeadScale * i / 10
    HD.DepthScale = DepthScale * i / 10
    HD.WidthScale = WidthScale * i / 10
    HD.HeightScale = HeightScale * i / 10

    Humanoid:ApplyDescription(HD)
    wait(.2)
end

Same result occured. This is weird

I haven’t looked at your script much but there are some values inside the humanoid (i think) where you can change the height, width, etc. scale. You can use TweenService to shrink them smoothly

1 Like

Here, try this:

local Touch
local RoundModule = require(script.RoundModule)
Touch = script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (Player)  then
		local NPS = Player:FindFirstChild("NormalPlayerSize")
		local P = Player:FindFirstChild("Piggy")
		if (NPS) and (not P) then
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			if Humanoid then
				local HD = Humanoid:GetAppliedDescription()
				for i = 1, 4 do
                   HD.HeadScale = HD.HeadScale * i/10
				   HD.DepthScale = HD.DepthScale * i/10
				   HD.WidthScale = HD.WidthScale * i/10
				   HD.HeightScale = HD.HeightScale * i/10
                end
				Humanoid:ApplyDescription(HD)
			end	
			NPS:Destroy()
			RoundModule.InsertTag(Player, "SmallPlayer")
		end
	end

end)

That makes the player too tiny.

TweenService can do this. Tween the Height Width and Depth values using TweenService

How would I do this with my current script?

When the player shrinks. Use TweenService for Tweening the Shrink. Use TweenService:Create() instead of Directly setting it

add a wait(0.2) after all 4 of the HD scales and before the end of the for l. Also try expertimenting with the numbers for different results.

Still did not work. I changed the values too.

Here is the script with the TweenService. I keep on receiving an error starting at HeadScale1:

local Touch
local RoundModule = require(script.RoundModule)
local TweenService = game:GetService("TweenService")
Touch = script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (Player)  then
		local NPS = Player:FindFirstChild("NormalPlayerSize")
		local P = Player:FindFirstChild("Piggy")
		if (NPS) and (not P) then
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			if Humanoid then
				local HD = Humanoid:GetAppliedDescription()
				
				local HeadScale1 = HD.HeadScale * .1
				local HeadScale2 = HD.HeadScale * .2
				local HeadScale3 = HD.HeadScale * .4
				local HeadScale4 = HD.HeadScale * .4
				
				local DepthScale1 = HD.DepthScale * .1
				local DepthScale2 = HD.DepthScale * .2
				local DepthScale3 = HD.DepthScale * .3
				local DepthScale4 = HD.DepthScale * .4
				
				local WidthScale1 = HD.WidthScale * .1
				local WidthScale2 = HD.WidthScale * .2
				local WidthScale3 = HD.WidthScale * .3
				local WidthScale4 = HD.WidthScale * .4
				
				local HeightScale1 = HD.HeightScale * .1
				local HeightScale2 = HD.HeightScale * .2
				local HeightScale3 = HD.HeightScale * .3
				local HeightScale4 = HD.HeightScale * .4
				
				local tweenInfo = TweenInfo.new(.2)
				
				local tweenHeadScale1 = TweenService:Create(HD.HeadScale, tweenInfo, HeadScale1)
				local tweenHeadScale2 = TweenService:Create(HD.HeadScale, tweenInfo, HeadScale2)
				local tweenHeadScale3 = TweenService:Create(HD.HeadScale, tweenInfo, HeadScale3)
				local tweenHeadScale4 = TweenService:Create(HD.HeadScale, tweenInfo, HeadScale4)
				
				local tweenDepthScale1 = TweenService:Create(HD.DepthScale, tweenInfo, DepthScale1)
				local tweenDepthScale2 = TweenService:Create(HD.DepthScale, tweenInfo, DepthScale2)
				local tweenDepthScale3 = TweenService:Create(HD.DepthScale, tweenInfo, DepthScale3)
				local tweenDepthScale4 = TweenService:Create(HD.DepthScale, tweenInfo, DepthScale4)
				
				local tweenWidthScale1 = TweenService:Create(HD.WidthScale, tweenInfo, WidthScale1)
				local tweenWidthScale2 = TweenService:Create(HD.WidthScale, tweenInfo, WidthScale2)
				local tweenWidthScale3 = TweenService:Create(HD.WidthScale, tweenInfo, WidthScale3)
				local tweenWidthScale4 = TweenService:Create(HD.WidthScale, tweenInfo, WidthScale4)
				
				local tweenHeightScale1 = TweenService:Create(HD.HeightScale, tweenInfo, HeightScale1)
				local tweenHeightScale2 = TweenService:Create(HD.HeightScale, tweenInfo, HeightScale2)
				local tweenHeightScale3 = TweenService:Create(HD.HeightScale, tweenInfo, HeightScale3)
				local tweenHeightScale4 = TweenService:Create(HD.HeightScale, tweenInfo, HeightScale4)
				
				tweenHeadScale1:Play()
				tweenDepthScale1:Play()
				tweenWidthScale1:Play()
				tweenHeightScale1:Play()
				Humanoid:ApplyDescription(HD)
				wait(1)
				tweenHeadScale2:Play()
				tweenDepthScale2:Play()
				tweenWidthScale2:Play()
				tweenHeightScale2:Play()
				Humanoid:ApplyDescription(HD)
				wait(1)
				tweenHeadScale3:Play()
				tweenDepthScale3:Play()
				tweenWidthScale3:Play()
				tweenHeightScale3:Play()
				Humanoid:ApplyDescription(HD)
				wait(1)
				tweenHeadScale4:Play()
				tweenDepthScale4:Play()
				tweenWidthScale4:Play()
				tweenHeightScale4:Play()
				Humanoid:ApplyDescription(HD)
			-- 	HD.HeadScale = HD.HeadScale * .4
			--	HD.DepthScale = HD.DepthScale * .4
			--	HD.WidthScale = HD.WidthScale * .4
			--	HD.HeightScale = HD.HeightScale * .4
			end	
			NPS:Destroy()
			RoundModule.InsertTag(Player, "SmallPlayer")
		end
	end

end)

The error i receive is that it can’t cast it onto the object.

Does it have to do with the first and last parameter of the Tween:Create function?