What do you want to achieve? I wanna make transparncy 1 when clicked after 1 more 0
What is the issue? Doesnt change the part after once.
Error at 17
local button = script.Parent
local open = false
local part1 = script.Parent.Parent.Parent.CLOSE
local part2 = script.Parent.Parent.Parent.OPEN
button.MouseClick:Connect(function(plr)
if plr.TeamColor == BrickColor.new("Lapis") and open == false then
part1.Transparency = 1
part2.Transparency = 0
for _, decal in pairs(part1:GetChildren()) do
if decal:IsA('Texture') then
decal.Transparency = 1
for _, decal in pairs(part2:GetChildren()) do
if decal:IsA('Texture') then
decal.Transparency = 0
open = true
elseif plr.TeamColor == BrickColor.new("Lapis") and open == true then
part1.Transparency = 0
part2.Transparency = 1
for _, decal in pairs(part2:GetChildren()) do
if decal:IsA('Texture') then
decal.Transparency = 1
for _, decal in pairs(part1:GetChildren()) do
if decal:IsA('Texture') then
decal.Transparency = 0
open = false
end
end
end
end
end
end
end
end
end
end)```
Well for starters what is the error.
And second your code is not very readable for someone who does not know what it does so if you could leave comments on it that would help
local button = script.Parent
local open = false
local part1 = script.Parent.Parent.Parent.CLOSE
local part2 = script.Parent.Parent.Parent.OPEN
button.MouseClick:Connect(function(plr)
if plr.TeamColor == BrickColor.new("Lapis") then
if not open then
part1.Transparency = 1
part2.Transparency = 0
for _, decal in pairs(part1:GetChildren()) do
if decal:IsA('Texture') then decal.Transparency = 1 end
end
for _, decal in pairs(part2:GetChildren()) do
if decal:IsA('Texture') then decal.Transparency = 0 end
end
open = true
else
part1.Transparency = 0
part2.Transparency = 1
for _, decal in pairs(part2:GetChildren()) do
if decal:IsA('Texture') then decal.Transparency = 1 end
end
for _, decal in pairs(part1:GetChildren()) do
if decal:IsA('Texture') then decal.Transparency = 0 end
end
open = false
end
end
end)
Or if you want to make it a little more readable you could do something like this:
local button = script.Parent
local open = false
local part1 = script.Parent.Parent.Parent.CLOSE
local part2 = script.Parent.Parent.Parent.OPEN
local function ChangeTransparency(Frame, Transp)
Frame.Transparency = Transp
for _, child in pairs(Frame:GetChildren()) do
if child:IsA('Texture') then child.Transparency = Transp end
end
end
button.MouseClick:Connect(function(plr)
if plr.TeamColor == BrickColor.new("Lapis") then
if not open then
ChangeTransparency(part1, 1)
ChangeTransparency(part2, 0)
open = true
else
ChangeTransparency(part2, 1)
ChangeTransparency(part1, 0)
open = false
end
end
end)