Загрузка данных


local Players = game:GetService("Players")

-- ================= НАСТРОЙКИ =================
local Settings = {
	Width = 0.5,  -- ширина тела (1 = обычная, меньше = уже)
	Depth = 0.7,  -- толщина спереди-назад (1 = обычная)
}
-- =============================================

local function setX(motor, prop, x)
	local cf = motor[prop]
	motor[prop] = CFrame.new(x, cf.Y, cf.Z) * (cf - cf.Position)
end

local function torsoWidth(char)
	local t = char:FindFirstChild("UpperTorso") or char:FindFirstChild("Torso")
	return t and (math.floor(t.Size.X * 100 + 0.5) / 100) or nil
end

local function narrowR15(hum, char)
	print("[NarrowBody] ширина торса до:", torsoWidth(char))

	local ok, desc = pcall(function()
		return hum:GetAppliedDescription()
	end)
	if ok and desc then
		desc.WidthScale = Settings.Width
		desc.DepthScale = Settings.Depth
		local ok2, err = pcall(function()
			hum:ApplyDescription(desc)
		end)
		if not ok2 then warn("[NarrowBody] ApplyDescription:", err) end
	else
		warn("[NarrowBody] не получил описание аватара")
	end

	task.wait(1)

	-- запасной способ: те же значения напрямую
	local w = hum:FindFirstChild("BodyWidthScale")
	local d = hum:FindFirstChild("BodyDepthScale")
	if w and math.abs(w.Value - Settings.Width) > 0.01 then w.Value = Settings.Width end
	if d and math.abs(d.Value - Settings.Depth) > 0.01 then d.Value = Settings.Depth end

	task.wait(0.5)
	print("[NarrowBody] ширина торса после:", torsoWidth(char))
end

local function narrowR6(char)
	local W, D = Settings.Width, Settings.Depth

	local torso = char:WaitForChild("Torso")
	local leftArm = char:WaitForChild("Left Arm")
	local rightArm = char:WaitForChild("Right Arm")
	local leftLeg = char:WaitForChild("Left Leg")
	local rightLeg = char:WaitForChild("Right Leg")

	local rs = torso:WaitForChild("Right Shoulder")
	local ls = torso:WaitForChild("Left Shoulder")
	local rh = torso:WaitForChild("Right Hip")
	local lh = torso:WaitForChild("Left Hip")

	local tw = 2 * W
	local aw = 1 * W
	local lw = 1 * W

	torso.Size = Vector3.new(tw, torso.Size.Y, 1 * D)
	leftArm.Size = Vector3.new(aw, leftArm.Size.Y, 1 * D)
	rightArm.Size = Vector3.new(aw, rightArm.Size.Y, 1 * D)
	leftLeg.Size = Vector3.new(lw, leftLeg.Size.Y, 1 * D)
	rightLeg.Size = Vector3.new(lw, rightLeg.Size.Y, 1 * D)

	setX(rs, "C0", tw / 2)
	setX(rs, "C1", -aw / 2)
	setX(ls, "C0", -tw / 2)
	setX(ls, "C1", aw / 2)
	setX(rh, "C0", lw)
	setX(rh, "C1", lw / 2)
	setX(lh, "C0", -lw)
	setX(lh, "C1", -lw / 2)

	print("[NarrowBody] R6 ширина торса:", torsoWidth(char))
end

local function onCharacter(plr, char)
	local hum = char:WaitForChild("Humanoid")
	print("[NarrowBody] тип аватара:", hum.RigType.Name)

	if hum.RigType == Enum.HumanoidRigType.R15 then
		-- ждём, пока загрузится внешность, иначе она вернёт обычную ширину
		local loaded = false
		local conn = plr.CharacterAppearanceLoaded:Connect(function(ch)
			if ch == char then loaded = true end
		end)
		local waited = 0
		while not loaded and waited < 6 do
			task.wait(0.25)
			waited += 0.25
		end
		conn:Disconnect()

		narrowR15(hum, char)
	else
		task.wait(0.3)
		narrowR6(char)
	end
end

local function onPlayer(plr)
	plr.CharacterAdded:Connect(function(char)
		onCharacter(plr, char)
	end)
	if plr.Character then
		task.spawn(onCharacter, plr, plr.Character)
	end
end

Players.PlayerAdded:Connect(onPlayer)
for _, plr in ipairs(Players:GetPlayers()) do
	onPlayer(plr)
end