Werid Jitter When Scaling Character In Script

Hey, im working on game where when a player touches a part they get bigger using custom characters. But we have run into a issue where when we update the scale of the character we get a weird jitter have no idea how to fix it

local module = {}

function module.Calculate(Player : Player)
	if Player then
		local Character = Player.Character
		if not Character then return false end

		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		local HRP = Character:FindFirstChild("HumanoidRootPart")
		local Torso = Character:FindFirstChild("Torso")

		if not Humanoid or not HRP or not Torso then return false end

		local MeshSize = HRP:FindFirstChildOfClass("SpecialMesh")

		local success, errorMsg = pcall(function()
			if MeshSize then
				local CharacterScale : number = Character:GetScale()
				print(CharacterScale)
				Character:ScaleTo(Character:GetScale() + 0.01)
				local scale = Character:GetScale() * 2
				Humanoid:WaitForChild("BodyDepthScale").Value = scale
				Humanoid:WaitForChild("BodyHeightScale").Value = scale
				Humanoid:WaitForChild("BodyWidthScale").Value = scale
				Humanoid.HipHeight = Character:GetScale()
				Player:WaitForChild("Data").Size.Value += 1
				Humanoid.WalkSpeed = 12
				Humanoid.JumpPower = 0
			end
		end)

		if not success then
			warn("Error during scaling tween: " .. errorMsg)
			return false
		end
		
		return true
	end

	return false
end

return module
3 Likes

the issue: https://www.youtube.com/watch?v=Xew4ohqhc5I

2 Likes

it might be because you’re using WaitForChild when accessing the body scales everytime the function runs, instead just declare the body scales once, also it depends if you’re calling the function on the client or server(server is slower)

edit: use humanoiddescriptions instead