Transparancy Change For All Parts With One Name

Im Trying To Make It So When I Click The Textbutton is changes all the parts with the same name to transparency 0 but when i do it, it only changes one of the parts

local tool = game.Players.LocalPlayer.Backpack.Pizza

local Onion = tool.Onion

script.Parent.MouseButton1Click:Connect(function()

Onion.Transparency = 0

end)

1 Like

You could use a for loop

for i, part in pairs(workspace:GetDescendants()) do
	if part.Name == "Onion" then
		--do stuff
	end
end

Would that work for a text button?

Yes it would work, try it and tell me if there are any errors.

Just place that in a MouseButton1Click, then it will.

Were would i paste it in the current code i have?

It will if you add script.Parent.MouseButton1:Connect((function()) In it which obviously fires the i,part function thing everytime you click a button

Where you set the one onions transparency.

It still only changes 1 of the onions

this is what i did is this wrong? local tool = game.Players.LocalPlayer.Backpack.Pizza
local Onion = tool.Onion
script.Parent.MouseButton1Click:Connect(function()

for i, part in pairs(workspace:GetDescendants()) do
	if part.Name == "Onion" then
		--do stuff
	end
end
Onion.Transparency = 0

end)

local Onion = tool.Onion
script.Parent.MouseButton1Click:Connect(function()

for i, part in pairs(workspace:GetDescendants()) do
	if part.Name == "Onion" then
		part.Transparency = 0
	end
end
end)

Thank you so much this really helps.