Is it possible to use localtransparencymodifier on accesories?

I have not been able to figure out how to do so. I’m working on a camera system that is focused at the players head, but any time i zoom in, accessories don’t fade or anything. i have not been able to find anything similar to this

Code : (Its A LocalScript)

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

char.Humanoid.CameraOffset = Vector3.new(0, 0, -1)

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
	elseif v:IsA("Accessory") then
		v.Handle:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			v.Handle.LocalTransparencyModifier = v.Handle.Transparency
		end)
	end
end
RunService.RenderStepped:Connect(function(step)
	local Camera = game.Workspace.CurrentCamera
	Camera.CameraSubject = char.Head
	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 = Vector3.new(0, 0, -1)
	end
end)

please let me know if i did something wrong
Any form of help is appreciated.

1 Like

Hi!
One solution that worked for me was looping through each accessory in the players character, looping through it’s parts and setting their LocalTransparencyModifier inside RenderStepped.

Example:

game:GetService("RunService").RenderStepped:Connect(function()
	for _, accessory in pairs(Character:GetChildren()) do
		if accessory:IsA("Accessory") then
			for _, part in pairs(accessory:GetDescendants()) do
				if part:IsA("BasePart") then
					part.LocalTransparencyModifier = 0
				end
			end
		end
	end
end)

I hope this helps!

It completely makes them transparent regardless of being zoomed in or not?
maybe it has something to do with being zoomed in on the head? if it does then I don’t really know how to fix that.
I could be doing something wrong.

2 Likes

My bad, I misunderstood your question.

What you could do is check the magnitude between the camera and the head of the character, and if it’s below a certain value, make everything transparent. Try this:

local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Camera = workspace:WaitForChild("Camera")
local DistanceCheck = 2

RunService.RenderStepped:Connect(function()
	if (Camera.CFrame.Position - Head.Position).Magnitude <= DistanceCheck  then
		for _, part in pairs(Character:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Transparency = 1
                part.LocalTransparencyModifier = 1
			end
		end
	else
		for _, part in pairs(Character:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Transparency = 0
                part.LocalTransparencyModifier = 0
			end
		end
	end
end)