Using GetDescendants With Click Detector Only Changes One Part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Use two seperate buttons within a model to change the transparency of all bricks within a given model from 0.5 with one button to 1 with the other button

  2. What is the issue? Include screenshots / videos if possible!
    Using getDescendants only 1 part in the group is changing transparency.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried changing between getchildren and getdescendants, no luck

Button 1 and 2 are the same script with different transparencies. Works great, just click the different button to change it back and forth. My problem is it only changes one part within the group “Model8”

local Parts = game.Workspace.Model.Model8:GetDescendants()
for i,v in pairs(Parts) do
	function onClicked()
	v.Transparency = 1
	end

end
	script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 Like

script.PNG
script2

local Parts = game.Workspace.Model.Model8:GetDescendants()
local function onClicked()
	for i,v in pairs(Parts) do
		v.Transparency = 1	
	end
end	

script.Parent.ClickDetector.MouseClick:connect(onClicked)

You can try this, this onClicked function will loop through the parts and set their transparency to 1.

1 Like

As Den has said, you’ve wrapped the function around transparency, rather than the loop, you want the loop to run each time its clicked, therefore the function needs to wrap around the entire loop.

1 Like

That fixed it perfectly thank you so much!