Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Any idea why this code leaves everything but the head and hats at .05 transparency?

When I begin to make the character invisible, it goes completely invisible like i want it to, but when it comes back to become visible again, it leaves the rest of your body besides your head a torso at .05 transparency, Why?.

GIF

In the GIF you can see that everything but the head and hat are semi transparent (.05 transparency to be exact)

Here is some of the code:

--This is the LocalScript that detects when you press the button K 
		if workspace:FindFirstChild(player.Name..'Mark') == nil then
			local ws = player.Character.Humanoid.WalkSpeed 
			local jp = player.Character.Humanoid.JumpPower
			CanCast = false
			
			player.Character.Humanoid.WalkSpeed = 0 
			player.Character.Humanoid.JumpPower = 0
			
			sound:FireServer('FXTarg',0, player)
			sound:FireServer('Mark', 0, player)
			sound:FireServer('Sound', player.Character.Head)
			sound:FireServer('Invis')  --The event that makes u turn invisible
			
			wait(2)
			
			player.Character.Humanoid.WalkSpeed = ws
			player.Character.Humanoid.JumpPower = jp
			
			sound:FireServer('Warp', 0, player) 
			--sound:FireServer('lol') 
			wait(COOLDOWN)
			CanCast = true
		end
--The part that runs when the Invis event is triggered

elseif task == 'Invis' then 		
		 local parts = plr.Character:GetChildren()
		 local fadeable = true
		
		while fadeable do 
			wait(.05)
			print('Running') 
		for i,v in pairs(parts) do
			if v.Name ~= 'HumanoidRootPart' and v.ClassName == 'Part' and v.Transparency < 1 then
				v.Transparency = v.Transparency +.05
			elseif v.ClassName == 'Hat' then 
				v.Handle.Transparency = v.Handle.Transparency +.05
			elseif v.Name ~= 'HumanoidRootPart' and v.ClassName == 'Part' and v.Transparency >= 1 then
				print('broke fade')
				print(v)
				fadeable = false
				wait(2)
				
				local partz = plr.Character:GetChildren()
		 		local fadeablez = true
				 while fadeablez do 
					wait(.05)
					print('running')
					for i,v in pairs(partz) do 
						if v.Name ~= 'HumanoidRootPart' and v.ClassName == 'Part' and v.Transparency > -0 then 
							v.Transparency = v.Transparency -.05
						elseif v.ClassName == 'Hat' then 
							v.Handle.Transparency = v.Handle.Transparency -.05
						elseif v.Name ~= 'HumanoidRootPart' and v.ClassName == 'Part' and v.Transparency <= -0 then
							print('broke unfade')
							fadeablez = false 
							break
						end
					end
				end

1 comment

0

The reason why i am using remote events is because the game has FilteringEnabled set to true.

1 answer

Solution

I don't know, but I am positive it was your revealing mechanism that caused it.

Code

I collected the parts in the first loop and again in case of changes. e.g: Picking up hats

for _, v in pairs(plr.Character:GetChildren()) do

end

This checker is for the hats, if its a hat then grab the real hat.

if v:IsA('Hat') then v = v.Handle end

This checker ignores the HumanoidRootPart plus it checks if v is a part. Includes wedges, corners ect.

if v.Name ~= 'HumanoidRootPart' and v:IsA('BasePart') then 

Heres your best friend, he runs from 0 to 1 in intervals of .05. The second for loop runs from 1 to 0 with same interval.

for i = 0, 1, 0.5 do

end

I set the wait time and the transparency of the part.

wait(0.05);
v.Transparency = i; 
elseif task == 'Invis' then
	for _, v in pairs(plr.Character:GetChildren()) do 
		if v:IsA('Hat') then v = v.Handle end
		if v.Name ~= 'HumanoidRootPart' and v:IsA('BasePart') then
			for i = 0, 1, 0.5 do
				wait(0.05); 
				v.Transparency = i; 
			end
		end
	end

	wait(2); -- Wait two seconds looking as

	for _, v in pairs(plr.Character:GetChildren()) do
		if v:IsA('Hat') then v = v.Handle end
		if v.Name ~= 'HumanoidRootPart' and v:IsA('BasePart') then
			for i = 1, 0, -0.5 do
				wait(0.05);
				v.Transparency = i;
			end
		end
	end	
end

This discussion is preserved as it was. New answers, comments, and votes are closed.