Is there a way to check if a instance has something like transparency

im using :GetDecendants() and theres differernt things like parts unions and meshes inside of the model and im trying to have to so if it has a transparency its set to 1
but im unsure if theres a way other then going along the line of

if v:IsA("MeshPart") or v:IsA("Part")  -- ect ect ect

and just kinda doing something like

if v.Transparency then v.Transparency = 1 end -- Errors obvis
1 Like

To Avoid those errors, you can use a pcall()

Its success will determine whether it actually was successful in finding the property, or if it had failed, if it was successful, it means it was found in the Property, otherwise it is false, which would cause an error, but pcall() is there to help avoid these errors.

local function HasTransparency(Instance)
    local success = pcall(function() -- pcall() in place to avoid errors
        local x = Instance.Transparency -- attempts to get Transparency
    end)
    return success -- returns whether it was sucessful for not
end


print(HasTransparency(workspace)) --> false
print(HasTransparency(workspace.Baseplate)) --> true

However, Remember to only use pcall() on things that you cant really control where errors occur, not where ever you like to use them.

If you want to Modify it to look for more than Transparency, you can!

2 Likes

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