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

Changing the property of parts with the exact same name?

Hello! I'm making a script where when I click on a button, the property of multiple parts with the same name gets changed, but I can't make it work. What have I done wrong?

local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(clicked)
    for i,v in pairs(workspace:GetChildren()) do
        if v:IsA("Part") then
            if v.Name == "Name" then
                if v.Transparency == 0.8 then
                    v.Transparency = 1
                elseif v.Transparency == 1 then
                    v.Transparency = 0.8
                end
            end
        end
    end
end)

1 answer

✓ Accepted answer
local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local partname = "transparencypart"

ClickDetector.MouseClick:Connect(function()
    for i,v in pairs(workspace:GetChildren()) do if v.Name == partname and v.ClassName == "Part" then if v.Transparency == 1 then v.Transparency -= .2 else v.Transparency += .2 end end end
end)

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