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


local Players = game:GetService("Players")

-- ================= НАСТРОЙКИ =================
local Settings = {
	Width = 0.7,  -- ширина тела (1 = обычная, меньше = уже)
	Depth = 0.8,  -- толщина спереди-назад (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 narrowR15(hum)
	local w = hum:WaitForChild("BodyWidthScale", 5)
	local d = hum:WaitForChild("BodyDepthScale", 5)
	if not w or not d then
		warn("[NarrowBody] Не нашёл масштаб тела у R15")
		return
	end
	print("[NarrowBody] было:", w.Value, d.Value)
	w.Value = Settings.Width
	d.Value = Settings.Depth
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)
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)
		task.wait(1)
		narrowR15(hum)  -- повторно, на случай отката
		local w = hum:FindFirstChild("BodyWidthScale")
		print("[NarrowBody] стало:", w and w.Value)
	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