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

How to grab models and items within. Read more please?

I am trying to make an invisibility script. I need to make the morph go too, however I do not want to manually grab every model and item. How can I grab multiple models, and make the meshes and unions inside get a transparency of 1 then 0.

Here is what I currently have I will bold where I need help.


local tool = script.Parent
local plr = game.Players.localPlayer
 origface = ''
wait()
local char = plr.Character
script.visible.Value = true

tool.Activated:connect(function()
	if script.visible.Value == true then
		script.visible.Value = false
	for _,v in pairs(char:GetChildren()) do
		if v:IsA('BasePart') then
			v.Transparency = 1
		elseif v:IsA('Accessory') then
			for name, child in pairs(v:GetChildren()) do -- Looping through all of the children
			if child:IsA("BasePart") then -- Checking if it's a part
			child.Transparency = 1 -- Transparency
			end
			end
			for name, child in pairs(v:GetChildren()) do -- Looping through all of the children
			if child:IsA("Model") then -- Checking if it's a part
			for name, child in pairs(child:GetChildren()) do
			for i = 1, #child do
				if child:IsA("UnionOperation") or child:IsA("MeshPart") then
			child.Transparency = 1
				end
				end
			end	
			end
		if char.Head.Name == 'Head' then
			origface = char.Head.face.Texture
			wait()
			print(origface)
			char.Head.face.Texture = 'http://www.roblox.com/asset/?id=0'
			print(origface)
		end 
			end
		end
	end
else
			script.visible.Value = true
		print(origface)
	for _,v in pairs(char:GetChildren()) do
		if v:IsA('BasePart') and v.Name ~= 'HumanoidRootPart' then
			v.Transparency = 0
		elseif v:isA('Accessory') then
			for name, child in pairs(v:GetChildren()) do -- Looping through all of the children
			if child:IsA("BasePart") then -- Checking if it's a part
			child.Transparency = 0 -- Transparency
			end
			end
			for _,v in pairs(char:GetChildren()) do
			if v:IsA('Model') then
								
				
				local morph = v:GetChildren()
				for i = 1, #morph do
					morph.Transparency = 0
				end
				end

		if char.Head.Name == 'Head' then
			print(origface)
			char.Head.face.Texture = origface
			print(origface)
		end
		end
	end
	end
	end
	end)

1 answer

✓ Accepted answer

Just use function GetDescendants which returns an array of the an instance's children, their children, etc.

Example:

for _,b in pairs(workspace:GetDescendants())do
 pcall(function()
  print(b.Name)
 end)
end

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