Making a human model go transparent?

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
1 Like

Not sure but shouldn’t the or’s be and’s?

2 Likes

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)

1 Like

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.

3 Likes
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

This?

2 Likes

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
1 Like

I tried this recently and this worked! Thank you very much for the help:)

I’m pretty sure my variable is not defined to my Humanoid as I use the :GetChildren() function on the model with the parts

I actually knew there was a function that filtered the parts by its object type but I wasn’t too sure. Glad to hear that it is a thing tho:D

I haven’t tried this but by the looks of it, it should work so I might be using this code:)

Oh, I never knew you could do that… Thank you very much!

By the way, I’m really sorry if my replies are 20 hours late due to school… But thank you to everyone who has helped me out with this problem!

1 Like

No worries. Please also mark the appropriate solution, so other people can also troubleshoot if they have similar problems.

Oh I just noticed that I did mark the wrong solution. I will try to change it if it is possible:)