Hello! I am trying to make a code where it lets a humanoid model go transparent. However, I really don’t know a lot about how to achieve this. I made this code that should work but somehow creates an error… I wish to further expand my knowledge on scripting so your help will truly benefit me a lot:) Thank you in advance!
The code:
for _, driver in pairs (driver_alive) do
if driver.Name ~= "Body Colors" or driver.Name ~= "Pants" or driver.Name ~= "Shirt" or driver.Name ~= "Hat" or driver.Name ~= "Humanoid" then
if driver.Material == Enum.Material.Plastic then
driver.Transparency = 1
end
end
if driver.Name == "Hat" then
driver.Handle.Transparency = 1
end
end
The error:
21:24:28.735 - Material is not a valid member of Humanoid
21:24:28.739 - Stack Begin
21:24:28.741 - Script 'ServerScriptService.Main', Line 122
21:24:28.742 - Stack End
It looks your “driver” is defined as your humanoid, the humanoid shouldn’t have any of the character parts inside of it giving you the problem, “Material is not a valid member of humanoid.” Btw the or’s should be and’s @RamJoT (sorry miss spell)
To help find out what driver is, print it like so: print(driver.Name)
They definitely should be ands, because now anything will be able to go through the first if statement. Try print(false ~= true or true ~= true); it’s true despite true being equal to true. You’ll see that the condition in the original post would also go through either if the driver isn’t BodyColors or if the driver isn’t Pants. If the driver is Pants, it can’t also be BodyColors, so it goes through the if statement fine.
Despite the fact that using and would technically work, a cleaner solution might be to check if driver:IsA("BasePart") instead, since Material is a property inherited from the BasePart class.
for _, driver in pairs (driver_alive) do
if driver:IsA("BasePart") then
if driver.Material == Enum.Material.Plastic then
driver.Transparency = 1
end
end
if driver.Name == "Hat" then
driver.Handle.Transparency = 1
end
end
Hats of a character may have a different class or be buried somewhere. Cleanest solution is to run this code on every BasePart that descends the driver model and rather than to check what something is not, to check what something is.
Here’s a code sample. I’m working off a very limited basis but it appears that your code works aside from the class check. Any issues here should be debugged on your own time.
-- driver_alive, whatever it is, should be a table fetched from GetDescendants
for _, part in ipairs(driver_alive) do
if part:IsA("BasePart") and part.Material.Name == "Plastic" then
part.Transparency = 1
end
end