R6 Scaling Head Floating

  1. What do you want to achieve?
    I’m having trouble fixing scaling, the head floats when too tall, or head goes into torso when short.

  2. What is the issue?
    Screenshot 2023-11-06 063446
    Screenshot 2023-11-06 063514

  3. What solutions have you tried so far?
    I have tried find solutions, none worked so far.


local Character = script.Parent

local function ScaleTo(Size)
	local PartSize = Vector3.new(1, Size, 1)
	local CurrentSize = Character:GetAttribute("CurrentSize") or 1
	local CurrentVector = Vector3.new(1, CurrentSize, 1)

	local Humanoid = Character.Humanoid

	local function AdjustMotor(Motor: Motor6D)
		local DefaultC0 = CFrame.new((Motor.C0.Position / CurrentVector)) * (Motor.C0 - Motor.C0.Position)
		local DefaultC1 = CFrame.new((Motor.C1.Position / CurrentVector)) * (Motor.C1 - Motor.C1.Position)

		Motor.C0 = CFrame.new((DefaultC0.Position * PartSize)) * (DefaultC0 - DefaultC0.Position)
		Motor.C1 = CFrame.new((DefaultC1.Position * PartSize)) * (DefaultC1 - DefaultC1.Position)

		if Motor.Name == "Neck" then
			--	Motor.C0 = CFrame.new((DefaultC0.Position * PartSize)) * (DefaultC0 - DefaultC0.Position)
			--	Motor.C1 = CFrame.new((DefaultC1.Position * PartSize)) * (DefaultC1 - DefaultC1.Position)
		end
	end

	AdjustMotor(Character.HumanoidRootPart.RootJoint)

	for _,Motor in ipairs(Character.Torso:GetChildren()) do
		if Motor:IsA("Motor6D") then
			AdjustMotor(Motor)
		end
	end



	for _,Part in ipairs(Character:GetDescendants()) do
		if Part.Name == "Head" then continue end

		if Part:IsA("BasePart") then
			Part.Size = (Part.Size / CurrentVector) * PartSize
		elseif Part:IsA("Accessory") then
			local Handle = Part.Handle
			local AccessoryWeld = Handle.AccessoryWeld

			local DefaultC0 = CFrame.new((AccessoryWeld.C0.Position / CurrentVector)) * (AccessoryWeld.C0 - AccessoryWeld.C0.Position)
			local DefaultC1 = CFrame.new((AccessoryWeld.C1.Position / CurrentVector)) * (AccessoryWeld.C1 - AccessoryWeld.C1.Position)

			AccessoryWeld.C0 = CFrame.new((DefaultC0.Position * PartSize)) * (DefaultC0 - DefaultC0.Position)
			AccessoryWeld.C1 = CFrame.new((DefaultC1.Position * PartSize)) * (DefaultC1 - DefaultC1.Position)

			local SpecialMesh = Handle:FindFirstChildOfClass("SpecialMesh")
			SpecialMesh.Scale = (SpecialMesh.Scale / CurrentVector) * PartSize
		end
	end

	Character:SetAttribute("CurrentSize", Size)
end

ScaleTo(2) -- Change this value 

Added new size by dividing the PartSize by 1.175.

Seems to work but not sure what you are needing it for.

local Character = script.Parent

local function ScaleTo(Size)
	
	local PartSize = Vector3.new(1, Size, 1)
	local HeadPartSize = Vector3.new(1, Size/1.175, 1) -- added new size

	local CurrentSize = Character:GetAttribute("CurrentSize") or 1
	local CurrentVector = Vector3.new(1, CurrentSize, 1)

	local Humanoid = Character.Humanoid

	local function AdjustMotor(Motor: Motor6D)
		local DefaultC0 = CFrame.new((Motor.C0.Position / CurrentVector)) * (Motor.C0 - Motor.C0.Position)
		local DefaultC1 = CFrame.new((Motor.C1.Position / CurrentVector)) * (Motor.C1 - Motor.C1.Position)

		Motor.C0 = CFrame.new((DefaultC0.Position * PartSize)) * (DefaultC0 - DefaultC0.Position)
		Motor.C1 = CFrame.new((DefaultC1.Position * PartSize)) * (DefaultC1 - DefaultC1.Position)

		if Motor.Name == "Neck" then
			Motor.C0 = CFrame.new((DefaultC0.Position * HeadPartSize)) * (DefaultC0 - DefaultC0.Position) -- used new size
			Motor.C1 = CFrame.new((DefaultC1.Position * HeadPartSize)) * (DefaultC1 - DefaultC1.Position) -- used new size
		end
	end

	AdjustMotor(Character.HumanoidRootPart.RootJoint)

	for _,Motor in ipairs(Character.Torso:GetChildren()) do
		if Motor:IsA("Motor6D") then
			AdjustMotor(Motor)
		end
	end



	for _,Part in ipairs(Character:GetDescendants()) do
		if Part.Name == "Head" then continue end

		if Part:IsA("BasePart") then
			Part.Size = (Part.Size / CurrentVector) * PartSize
		elseif Part:IsA("Accessory") then
			local Handle = Part.Handle
			local AccessoryWeld = Handle.AccessoryWeld

			local DefaultC0 = CFrame.new((AccessoryWeld.C0.Position / CurrentVector)) * (AccessoryWeld.C0 - AccessoryWeld.C0.Position)
			local DefaultC1 = CFrame.new((AccessoryWeld.C1.Position / CurrentVector)) * (AccessoryWeld.C1 - AccessoryWeld.C1.Position)

			AccessoryWeld.C0 = CFrame.new((DefaultC0.Position * PartSize)) * (DefaultC0 - DefaultC0.Position)
			AccessoryWeld.C1 = CFrame.new((DefaultC1.Position * PartSize)) * (DefaultC1 - DefaultC1.Position)

			local SpecialMesh = Handle:FindFirstChildOfClass("SpecialMesh")
			SpecialMesh.Scale = (SpecialMesh.Scale / CurrentVector) * PartSize
		end
	end

	Character:SetAttribute("CurrentSize", Size)
end

ScaleTo(2)

Unfortunately this doesn’t seem to work for my case (Changing the ‘ScaleTo(x)’ to another number moves the head), I am making a height system and need to figure out how to make the head not float or sink into torso regardless of the scaling.