I am trying to make a system for my custom camera where if there is a part in between your player and the camera, the part’s transparency turns half transparent. My ObscureCamera function is fired in a RenderStepped function.
local function ObscureCamera(Camera,Character)
-- transparency effects
Objects = Camera:GetPartsObscuringTarget({Character.HumanoidRootPart.Position},{})
-- add new obscuring parts to table
for _,obscuringPart in pairs(Objects) do -- for ever obscuring part do
local Object = GetModelParent(obscuringPart) or obscuringPart
if IsInTable(ObscuringPartsData,Object,false) == false then -- if the part is not already obscuring
if not IsClass(obscuringPart.Parent,{"Accessory"}) then -- if part isnt part of a filtered class
table.insert(ObscuringPartsData,Object)
if Object:IsA("Model") then
print("ISAMODEL")
for _,child in pairs(Object:GetDescendants()) do
if child:IsA("BasePart") then
child.LocalTransparencyModifier = 0.5
end
end
else
Object.LocalTransparencyModifier = 0.5
end
end
end
end
-- remove changed obscuring parts
for index,obscuringObject in pairs(ObscuringPartsData) do
local Object = GetModelParent(obscuringObject) or obscuringObject
if IsInTable(Objects,Object,false) == false then
if Object:IsA("Model") then
table.remove(ObscuringPartsData,index)
for _,child in pairs(Object:GetDescendants()) do
if child:IsA("BasePart") then
child.LocalTransparencyModifier = 0
end
end
else
table.remove(ObscuringPartsData,index)
Object.LocalTransparencyModifier = 0
end
end
end
end
So what I am trying to do is if the part is in a model then get the model and change all the children to half transparent. I can correctly get the main parent model with this function:
local function GetModelParent(Object)
if Object.Parent == workspace or Object.Parent:IsA("Folder") then
if Object.ClassName ~= "Model" then return nil end
--print(Object.Name)
return Object
else
return GetModelParent(Object.Parent)
end
end
My method works for if it’s just a part, but not for models. I will show both ways below:
Only a Part, no model
https://gyazo.com/abaccaa3b1d0ab37eaee7c973c50437e
Model Objects
https://gyazo.com/fe17766866adb9cba50568a75ce5bb11
For some reason, with models it is removing and I proved this by printing on the remove bit.
How can I make this work correctly?