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

Change multiple part's properties with a button?

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

✓ Accepted answer

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)

4 comments

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""

0

Yeah, I was wondering why you put MouseButton1Down. If you are using ClickDetector, just do Button.ClickDetector.MouseClick

0

Thanks for the guidance, it means a lot

0

np

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