Help with a transparency script

Hi,

Im currently having issues with this script:

local SetOne = script.Parent
local Button2 = game.Workspace.Button3
local Button3 = game.Workspace.Button3
local SetTwo = Button2 and Button3

function onTouch(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	SetTwo.Transparency = 0
end
script.Parent.Touched:connect(onTouch)

So Button 3 becomes visible but not button 2.

The output does not show any errors.

I hope someone can help.

From,
File

Both of your buttons are assigned to the same part, plus the “and” function doesn’t work this way:

local SetOne = script.Parent
local Button2 = game.Workspace.Button2
local Button3 = game.Workspace.Button3

function onTouch(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	Button2 .Transparency = 0
	Button3 .Transparency = 0
end
script.Parent.Touched:connect(onTouch)

so you can’t group them into one variable.

Correct. You cannot group them together like that.

You made a typo. Or is it supposed to be like that?

Yes, but if you really wanted to, you could create a table then do a for loop:

local SetOne = script.Parent
local Button2 = game.Workspace.Button2
local Button3 = game.Workspace.Button3
local SetTwo = {
	A = Button2,
	B = Button3
}
function onTouch(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	for i,v in pairs(SetTwo) do
		v.Transparency = 0
	end
end
script.Parent.Touched:connect(onTouch)

oh. Thats why I think. Maybe. Im going to test it.

can you change A and B to anything you like?

also when you add a new line in a table do you do a comma?

The names can be anything. If you want spaces in the name you would have to format it like so:

local exampleTable = {
     ["My Variable"] = "value",
     MyVariable2 = true,
     MyVariable3 = game.Workspace.Part
}

exampleTable["My Variable"] = "new value"
exampleTable.MyVariable2 = false
exampleTable.MyVariable3.Transparency = 0

And yes you should put a comma on every new line but the last line does not require it.

code with camelCase
local setOne = script.Parent
local setTwo = {
    workspace.Button2,
    workspace.Button3
}

function onTouch(part)
    local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")

    for _, button in ipairs(setTwo) do
        button.Transparency = 0
    end
end

setOne.Touched:Connect(onTouch)
code with PascalCase
local SetOne = script.Parent
local SetTwo = {
    workspace.Button2,
    workspace.Button3
}

function OnTouch(Part)
    local Humanoid = Part.Parent:FindFirstChildOfClass("Humanoid")

    for _, Button in ipairs(SetTwo) do
        Button.Transparency = 0
    end
end

SetOne.Touched:Connect(OnTouch)

made some changes to the code
also choose camelCase or PascalCase, don’t just mix both of them

also what are I v pairs? I heard them before.

Use for for loops for iterations. I recommend you to not do this script yet if you haven’t got the basics of the scripting done yet.

I got a bit fo it done. Like a couple things but I still dont know much.

It’s not ideal to learn these right away, but if you feel inclined you can read more here.

As @7rippy said, if you aren’t experienced in doing one thing, then don’t do it until you gain the knowledge.