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

Changing the property of parts with the exact same name?

Asked by
YTWolFs 11
3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
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)
Ad

Answer this question