Invisiblty code not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make invisibility code so when part transparency is 1 it be 0 and when it’s 0 it be 1
  2. What is the issue? Include screenshots / videos if possible!
    when it’s invisible I want to turn it to uninvisibility and for some reason it don’t, and am sure that it’s not named HumanoidRootPart and transparency==1(i made another if statement and it worked)
  3. What solutions have you tried so far? Did you look for solutions on the
    Much of debugging
	for i,v in ipairs(character:GetChildren()) do
			if v:IsA("BasePart") then
				print("PASSED")
				local x=0		
				--Here we handle the part Transparency so it be invisible 
				--if transparency==1 then its invisible and you know what we should do
				print(v.Transparency,v.Name,x)
				if v.Transparency==1 and not v.Name=="HumanoidRootPart" then
					print("PASSED3")
					x=1

					v.Transparency=0
				end
				print("c")
				if v.Transparency==1 then
					print("x")
				end
				if v.Transparency==0 and x==0 then
						print("PASSED2")
					v.Transparency=1
				end
				--Here we handled the parts 
			end
 end

Can i see your output when you run game?

first:

  13:27:07.413  mustafahhh  -  Server - Other's handler:8
  13:27:07.414  PASSED  -  Server - Other's handler:40
  13:27:07.414  1 HumanoidRootPart 0  -  Server - Other's handler:44
  13:27:07.414  c  -  Server - Other's handler:51
  13:27:07.414  X  -  Server - Other's handler:53
  13:27:07.414  PASSED  -  Server - Other's handler:40
  13:27:07.415  0 LeftHand 0  -  Server - Other's handler:44
  13:27:07.415  c  -  Server - Other's handler:51
  13:27:07.415  PASSED2  -  Server - Other's handler:56
  13:27:07.415  PASSED  -  Server - Other's handler:40
  13:27:07.415  0 LeftLowerArm 0  -  Server - Other's handler:44
  13:27:07.416  c  -  Server - Other's handler:51
  13:27:07.416  PASSED2  -  Server - Other's handler:56
  13:27:07.416  PASSED  -  Server - Other's handler:40
  13:27:07.416  0 LeftUpperArm 0  -  Server - Other's handler:44
  13:27:07.416  c  -  Server - Other's handler:51
  13:27:07.417  PASSED2  -  Server - Other's handler:56
  13:27:07.417  PASSED  -  Server - Other's handler:40
  13:27:07.417  0 RightHand 0  -  Server - Other's handler:44
  13:27:07.417  c  -  Server - Other's handler:51
  13:27:07.417  PASSED2  -  Server - Other's handler:56
  13:27:07.417  PASSED  -  Server - Other's handler:40
  13:27:07.418  0 RightLowerArm 0  -  Server - Other's handler:44
  13:27:07.418  c  -  Server - Other's handler:51
  13:27:07.418  PASSED2  -  Server - Other's handler:56
  13:27:07.418  PASSED  -  Server - Other's handler:40
  13:27:07.418  0 RightUpperArm 0  -  Server - Other's handler:44
  13:27:07.418  c  -  Server - Other's handler:51
  13:27:07.418  PASSED2  -  Server - Other's handler:56
  13:27:07.419  PASSED  -  Server - Other's handler:40
  13:27:07.419  0 UpperTorso 0  -  Server - Other's handler:44
  13:27:07.419  c  -  Server - Other's handler:51
  13:27:07.419  PASSED2  -  Server - Other's handler:56
  13:27:07.419  PASSED  -  Server - Other's handler:40
  13:27:07.419  0 LeftFoot 0  -  Server - Other's handler:44
  13:27:07.419  c  -  Server - Other's handler:51
  13:27:07.420  PASSED2  -  Server - Other's handler:56
  13:27:07.420  PASSED  -  Server - Other's handler:40
  13:27:07.420  0 LeftLowerLeg 0  -  Server - Other's handler:44
  13:27:07.420  c  -  Server - Other's handler:51
  13:27:07.420  PASSED2  -  Server - Other's handler:56
  13:27:07.420  PASSED  -  Server - Other's handler:40
  13:27:07.421  0 LeftUpperLeg 0  -  Server - Other's handler:44
  13:27:07.421  c  -  Server - Other's handler:51
  13:27:07.421  PASSED2  -  Server - Other's handler:56
  13:27:07.421  PASSED  -  Server - Other's handler:40
  13:27:07.421  0 RightFoot 0  -  Server - Other's handler:44
  13:27:07.421  c  -  Server - Other's handler:51
  13:27:07.422  PASSED2  -  Server - Other's handler:56
  13:27:07.422  PASSED  -  Server - Other's handler:40
  13:27:07.422  0 RightLowerLeg 0  -  Server - Other's handler:44
  13:27:07.422  c  -  Server - Other's handler:51
  13:27:07.422  PASSED2  -  Server - Other's handler:56
  13:27:07.423  PASSED  -  Server - Other's handler:40
  13:27:07.423  0 RightUpperLeg 0  -  Server - Other's handler:44
  13:27:07.423  c  -  Server - Other's handler:51
  13:27:07.423  PASSED2  -  Server - Other's handler:56
  13:27:07.423  PASSED  -  Server - Other's handler:40
  13:27:07.424  0 LowerTorso 0  -  Server - Other's handler:44
  13:27:07.424  c  -  Server - Other's handler:51
  13:27:07.424  PASSED2  -  Server - Other's handler:56
  13:27:07.424  PASSED  -  Server - Other's handler:40
  13:27:07.424  0 Head 0  -  Server - Other's handler:44
  13:27:07.424  c  -  Server - Other's handler:51
  13:27:07.425  PASSED2  -  Server - Other's handler:56

second:

  13:27:56.728  PASSED  -  Server - Other's handler:40
  13:27:56.728  1 HumanoidRootPart 0  -  Server - Other's handler:44
  13:27:56.729  c  -  Server - Other's handler:51
  13:27:56.729  X  -  Server - Other's handler:53
  13:27:56.729  PASSED  -  Server - Other's handler:40
  13:27:56.729  1 LeftHand 0  -  Server - Other's handler:44
  13:27:56.729  c  -  Server - Other's handler:51
  13:27:56.729  X  -  Server - Other's handler:53
  13:27:56.730  PASSED  -  Server - Other's handler:40
  13:27:56.730  1 LeftLowerArm 0  -  Server - Other's handler:44
  13:27:56.730  c  -  Server - Other's handler:51
  13:27:56.730  X  -  Server - Other's handler:53
  13:27:56.730  PASSED  -  Server - Other's handler:40
  13:27:56.731  1 LeftUpperArm 0  -  Server - Other's handler:44
  13:27:56.731  c  -  Server - Other's handler:51
  13:27:56.731  X  -  Server - Other's handler:53
  13:27:56.731  PASSED  -  Server - Other's handler:40
  13:27:56.732  1 RightHand 0  -  Server - Other's handler:44
  13:27:56.732  c  -  Server - Other's handler:51
  13:27:56.732  X  -  Server - Other's handler:53
  13:27:56.732  PASSED  -  Server - Other's handler:40
  13:27:56.732  1 RightLowerArm 0  -  Server - Other's handler:44
  13:27:56.732  c  -  Server - Other's handler:51
  13:27:56.733  X  -  Server - Other's handler:53
  13:27:56.733  PASSED  -  Server - Other's handler:40
  13:27:56.733  1 RightUpperArm 0  -  Server - Other's handler:44
  13:27:56.733  c  -  Server - Other's handler:51
  13:27:56.733  X  -  Server - Other's handler:53
  13:27:56.733  PASSED  -  Server - Other's handler:40
  13:27:56.734  1 UpperTorso 0  -  Server - Other's handler:44
  13:27:56.734  c  -  Server - Other's handler:51
  13:27:56.734  X  -  Server - Other's handler:53
  13:27:56.734  PASSED  -  Server - Other's handler:40
  13:27:56.734  1 LeftFoot 0  -  Server - Other's handler:44
  13:27:56.734  c  -  Server - Other's handler:51
  13:27:56.735  X  -  Server - Other's handler:53
  13:27:56.735  PASSED  -  Server - Other's handler:40
  13:27:56.735  1 LeftLowerLeg 0  -  Server - Other's handler:44
  13:27:56.735  c  -  Server - Other's handler:51
  13:27:56.735  X  -  Server - Other's handler:53
  13:27:56.735  PASSED  -  Server - Other's handler:40
  13:27:56.735  1 LeftUpperLeg 0  -  Server - Other's handler:44
  13:27:56.736  c  -  Server - Other's handler:51
  13:27:56.736  X  -  Server - Other's handler:53
  13:27:56.736  PASSED  -  Server - Other's handler:40
  13:27:56.736  1 RightFoot 0  -  Server - Other's handler:44
  13:27:56.736  c  -  Server - Other's handler:51
  13:27:56.736  X  -  Server - Other's handler:53
  13:27:56.736  PASSED  -  Server - Other's handler:40
  13:27:56.737  1 RightLowerLeg 0  -  Server - Other's handler:44
  13:27:56.737  c  -  Server - Other's handler:51
  13:27:56.737  X  -  Server - Other's handler:53
  13:27:56.737  PASSED  -  Server - Other's handler:40
  13:27:56.737  1 RightUpperLeg 0  -  Server - Other's handler:44
  13:27:56.738  c  -  Server - Other's handler:51
  13:27:56.738  X  -  Server - Other's handler:53
  13:27:56.738  PASSED  -  Server - Other's handler:40
  13:27:56.738  1 LowerTorso 0  -  Server - Other's handler:44
  13:27:56.738  c  -  Server - Other's handler:51
  13:27:56.738  X  -  Server - Other's handler:53
  13:27:56.739  PASSED  -  Server - Other's handler:40
  13:27:56.739  1 Head 0  -  Server - Other's handler:44
  13:27:56.739  c  -  Server - Other's handler:51
  13:27:56.739  X  -  Server - Other's handler:53

I fixed it instead of humanoid root part and the 1 transparency check in one statment i made the transparency the only in the statment and another code make the humanoidrootpart automatic make it self 1 transparency

1 Like

I suggest not using the x variable, it makes the code more complicated. Try this instead:

for i,v in ipairs(character:GetChildren()) do
	if v:IsA("BasePart") then
		if v.Transparency==1 and (v.Name~="HumanoidRootPart") then
			v.Transparency=0
		elseif v.Transparency==0 then
			v.Transparency=1
		end
	--Here we handled the parts 
	end
 end

Much shorter and easier to understand in my opinion.

1 Like
local character = script.Parent
wait(5)
function classes(class)
	if class == "Part" or class == "WedgePart" or class == "Decal" or class == "MeshPart" or class == "UnionOperation" then
		return true
	end
end
for i,v in pairs(character:GetDescendants()) do
	if classes(v.ClassName) and tostring(v) ~= "HumanoidRootPart" then
		v.Transparency = 1
	end
end

example of an invisibility script I made.

1 Like