Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with i,v in pairs?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

****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)

0
:GetChildren().Transparency = 1 haloelite27 25 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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
0
Technically the same. rexbit 707 — 8y
Ad

Answer this question