Making First Person Body script work with layered clothing

I have an FP Body script and I am trying to make it work with layered clothing.

Currently, it makes the clothing invisible, which also makes the player’s body invisible (Photo below)

I want to make it not do so, and show all of the layered clothing.

Photo

Script
local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")

local offset = Vector3.new(0, 0, -2)

char.Humanoid.CameraOffset = offset

for i, v in pairs(char:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Head" then

		v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			v.LocalTransparencyModifier = v.Transparency
		end)

		v.LocalTransparencyModifier = v.Transparency

	end
end

RunService.RenderStepped:Connect(function(step)
	local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
	local ignoreList = char:GetChildren()

	local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

	if hit then
		char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
	else
		char.Humanoid.CameraOffset = offset
	end
end)
1 Like

The issue you are encountering is caused by the fact that the code is setting the LocalTransparencyModifier property of all parts in the character to their Transparency value. This is essentially making all parts transparent, including the layered clothing.

To fix this issue, you should modify the script to only set the LocalTransparencyModifier property for parts that are not part of the layered clothing. You can do this by checking if the part’s parent is the character, and if it is not, then set the LocalTransparencyModifier property.

Here is an example of how you could modify the script to achieve this:

local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")

local offset = Vector3.new(0, 0, -2)

char.Humanoid.CameraOffset = offset

for i, v in pairs(char:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Head" and v.Parent == char then

		v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			v.LocalTransparencyModifier = v.Transparency
		end)

		v.LocalTransparencyModifier = v.Transparency

	end
end

RunService.RenderStepped:Connect(function(step)
	local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
	local ignoreList = char:GetChildren()

	local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

	if hit then
		char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
	else
		char.Humanoid.CameraOffset = offset
	end
end)

Note that in this modified script, we added a check to make sure that the part’s parent is equal to the character, which excludes parts that are part of the layered clothing.

1 Like

Replace :GetChildren() with :GetDescendants(). That’ s it.

1 Like

I’m stupid but I also figured this is what would fix it.

Thank you but this didn’t work.

The guy below figured it out though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.