How to make NPC Near invisible

So i am doing some skill, but can’t seem to figure how would i make all npc invisible in workspace, i tried this but it doesnt seems to work, sorry if the script is a mess

script.Parent.OnServerEvent:Connect(function(plr)
	local playerchar = plr.Character
	
	for index, players in pairs(game.Players:GetPlayers()) do -- Make players invisible
		print(players.Character.Head.Name)
	
		local character = players.Character
		print("i 1 ")
		if character:FindFirstChild("Humanoid") or character:FindFirstChild("NPC") then
		local mag = (character.HumanoidRootPart.Position - playerchar.HumanoidRootPart.Position).magnitude
		if mag <= 30 then
			
		for i, v in pairs(character:GetChildren()) do
					print("i 2")
		print(v)
	--	if v.Name == "Head" and not v.ClassName == "WrapTarget" then
		--	print("a2")
		--	v.face.Transparency = 1
		--end
		if v:IsA("Part") then
			--v.Transparency = 1
			local t = tweenService:Create(v, tInfo, {Transparency = 1})

			t:Play()
		end
		if v:IsA("Part") and v.Name == "Head" then
			local t = tweenService:Create(v, tInfo, {Transparency = 1})
			local t2 = tweenService:Create(v.face, tInfo, {Transparency = 1})

			t:Play()
			t2:Play()

			--	v.Transparency = 1
			--	v.face.Transparency = 1
				
			print("a3")
		end
		if v:IsA("Accessory") or v:IsA("Hat") then
			if v:FindFirstChild("Handle") then
				local yes = v:FindFirstChild("Handle")

				local t = tweenService:Create(yes, tInfo, {Transparency = 1})

				t:Play()
			end
		end
	end

		task.wait (30)
		for i, v in pairs(character:GetChildren())do
		if v:IsA("Part") then
			--v.Transparency = 1
			local t = tweenService:Create(v, tInfo, {Transparency = 0})

			t:Play()
		end
		if v:IsA("Part") and v.Name == "Head" then
			local t = tweenService:Create(v, tInfo, {Transparency = 0})
			local t2 = tweenService:Create(v.face, tInfo, {Transparency = 0})

			t:Play()
			t2:Play()

			--	v.Transparency = 1
			--	v.face.Transparency = 1

			print("a3")
		end
		if v:IsA("Accessory") or v:IsA("Hat") then
			if v:FindFirstChild("Handle") then
				local yes = v:FindFirstChild("Handle")

				local t = tweenService:Create(yes, tInfo, {Transparency = 0})

				t:Play()
			end
		end
		task.wait(0.1)
		if v.Name == "HumanoidRootPart" then
			local t = tweenService:Create(v, tInfo, {Transparency = 1})

			t:Play()
			t.Completed:Connect(function()
				v.Transparency = 1
			end)
		end
			end
			end
		end
	end

	for indexs, va in pairs(workspace:GetDescendants()) do -- Make NPC Invisible
print(" i 0zzz") -- It doesnt prints, i dont know why
		--local characterz = npc
		
			print("i 1zzz ")
		if va:FindFirstChild("Humanoid") or va:FindFirstChild("NPC") then
			print("siizzz")
				local mag = (va.HumanoidRootPart.Position - playerchar.HumanoidRootPart.Position).magnitude
				if mag <= 30 then

						print("i 2zzz")
						print(va)
						--	if v.Name == "Head" and not v.ClassName == "WrapTarget" then
						--	print("a2")
						--	v.face.Transparency = 1
						--end
						if va:IsA("Part") then
							--v.Transparency = 1
							local t = tweenService:Create(va, tInfo, {Transparency = 1})

							t:Play()
						end
						if va:IsA("Part") and va.Name == "Head" then
							local t = tweenService:Create(va, tInfo, {Transparency = 1})
							local t2 = tweenService:Create(va.face, tInfo, {Transparency = 1})

							t:Play()
							t2:Play()

							--	v.Transparency = 1
							--	v.face.Transparency = 1

							print("a3")
						end
						if va:IsA("Accessory") or va:IsA("Hat") then
							if va:FindFirstChild("Handle") then
								local yes = va:FindFirstChild("Handle")

								local t = tweenService:Create(yes, tInfo, {Transparency = 1})

								t:Play()
							end
				end
				task.wait (30)
				--for i, va in pairs(characterz:GetChildren())do
				if va:IsA("Part") then
					--v.Transparency = 1
					local t = tweenService:Create(va, tInfo, {Transparency = 0})

					t:Play()
				end
				if va:IsA("Part") and va.Name == "Head" then
					local t = tweenService:Create(va, tInfo, {Transparency = 0})
					local t2 = tweenService:Create(va.face, tInfo, {Transparency = 0})

					t:Play()
					t2:Play()

					--	v.Transparency = 1
					--	v.face.Transparency = 1

					print("a3")
				end
				if va:IsA("Accessory") or va:IsA("Hat") then
					if va:FindFirstChild("Handle") then
						local yes = va:FindFirstChild("Handle")

						local t = tweenService:Create(yes, tInfo, {Transparency = 0})

						t:Play()
					end
				end
				task.wait(0.1)
				if va.Name == "HumanoidRootPart" then
					local t = tweenService:Create(va, tInfo, {Transparency = 1})

					t:Play()
					t.Completed:Connect(function()
						va.Transparency = 1
					end)
				end
				--end
					end

				end
	end
end)

In your situation i just make invisible npcs model and put it in the lighting and then move it to workspace when the visible npc model goes to lighting one replaces another

1 Like