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

Change multiple part's properties with a button?

Asked by 3 years ago

I'm trying to create a button whereupon being clicked, changes the transparency of multiple parts with the same values but it won't work, I'm not that great with scripting so i don't really know what I'm doing wrong

local Button = workspace.LightButton1 -- where the button is located
local Lights = workspace.Row1:GetChildren() -- where multiple lights are located (in a group)

    Button.MouseButton1Down:Connect(function()
        if Lights.Transparency == 0 then
            Lights.Transparency = 1
        elseif Lights.Transparency == 1 then
            Lights.Transparency = 0
        end
    end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You need to switch each transparency property seperately. Fortunately you can easily do this with a for loop.

Button.MouseButton1Down:Connect(function() 
    for i, v in ipairs (workspace.Row1:GetChildren()) do
        if v.Transparency == 0 then
                v.Transparency = 1
            elseif v.Transparency == 1 then
                v.Transparency = 0
            end

    end
end)
0
thank you for the help but I think i'm missing something due to it not responding, and in my output it gives me " MouseButton1Down is not a valid member of ClickDetector "Workspace.LightButton1.Switch1"" RussianPiano 2 — 3y
0
Yeah, I was wondering why you put MouseButton1Down. If you are using ClickDetector, just do Button.ClickDetector.MouseClick JustinWe12 723 — 3y
0
Thanks for the guidance, it means a lot RussianPiano 2 — 3y
0
np JustinWe12 723 — 3y
Ad

Answer this question