I have meshparts welded to the player’s character and wanted them to turn semi-transparent/transparent when zooming in or out, like how the player does.
I learned that LocalTransparencyModifier is able to accomplish this, but I genuinely don’t understand how exactly I’m able to accomplish this. Is it as simple as adding a local script into every individual MeshPart and utilizing GetPropertyChangedSignal() or what?
Yes! Here’s a script that you can try. Just place this LocalScript in StarterPlayer > StarterCharacterScripts:
local plr = game.Players.LocalPlayer
plr.CharacterAppearanceLoaded:Connect(function(char)
for _, meshpart in pairs(char:GetDescendants()) do
if meshpart:IsA("MeshPart") then
meshpart.LocalTransparencyModifier = meshpart.Transparency
meshpart:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
meshpart.LocalTransparencyModifier = meshpart.Transparency
end)
end
end
end)
So, I modified the script to cater to what I was doing in my experience. Specifically, I went and changed it so that for any child added in a specific folder that carried all of the items the player was wearing at the time, it would go through the for loop and change the LocalTransparencyModifier.
Unfortunately, my adaptation isn’t making these parts semi-transparent nor transparent when zooming the camera in or out
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local plrfolder = workspace:WaitForChild("Items"):WaitForChild(plr.Name)
plrfolder.ChildAdded:Connect(function(child)
for _,part in child:GetDescendants() do
if part:IsA("MeshPart") or part:IsA("BasePart") then
part.LocalTransparencyModifier = part.Transparency
part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
part.LocalTransparencyModifier = part.Transparency
end)
end
end
end)
If I understand your code correctly, I don’t think you need a for loop there. You just have to check if the child is the meshpart/basepart now, instead of it’s descendants. You can just use this:
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local plrfolder = workspace:WaitForChild("Items"):WaitForChild(plr.Name)
plrfolder.ChildAdded:Connect(function(child)
if child:IsA("MeshPart") or child:IsA("BasePart") then
child.LocalTransparencyModifier = child.Transparency
child:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
child.LocalTransparencyModifier = child.Transparency
end)
end
end)
Oh, don’t worry, the for loop is because I have to iterate through a model to find either a MeshPart or BasePart.
In any case, though, I went through the TransparencyController module and experimented a bit… I guess I have to either edit TransparencyController to account for what I’m doing in my experience or specifically have the items INSIDE the player’s model in workspace. Otherwise, this won’t work.
So I guess I answered my own question? I dunno, very convoluted lol
EDIT:
It was simpler than I thought!
Just use GetPropertyChangedSignal() for any random part on the character and change the LocalTransparencyModifier to said part! Works like a charm, thank god