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

Help with i,v in pairs?

****What I am trying to do is, when I click on a button then all parts in the "PhoneOn" folder get transparent.

Button = script.Parent
Button.ClickDetector.MouseClick:connect(function()

	local Screen = script.Parent.Parent.Screen

	for i,v in pairs {Screen} do
		if v.Material == Enum.Material.SmoothPlastic then
			v.Material = Enum.Material.Neon
   		else
    		v.Material = Enum.Material.SmoothPlastic
		end
	end
	--Mostly worrying about the script below.
	local PhoneOn = script.Parent.Parent.Parent.PhoneOn --PhoneOn is the name of the folder with parts in it.
	
	for i,v in pairs (PhoneOn:GetChildren()) do
		if v:IsA("Part") then
			v.Transparency = 1
		end
	end
end)

1 comment

0

:GetChildren().Transparency = 1

1 answer

Why are you using the for ... in pairs loop? A generic for loop is much easier to follow.

local list = PhoneOn:GetChildren()
for i=1, #list do
	if list[i].IsA("Part") then
		list[i].Transparency = 1
	end
end

1 comment

0

Technically the same.

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