This script is very early and I am testing features. So currently I have an issue with the following script. What I want it to do is make all CL1, CL3, CL5, etc. have their surface GUI frame be visible all at the same time. Currently it will only change one at a time. Thus, I know the issue is where I have if b.Name == "CL1" or b.Name == "CL3" or b as it only selects one, not all. I assume this is because I use the term “or” and I was wondering how I can fix this efficiently. Thanks!
local Folder = workspace:WaitForChild("LineStobes")
local L1 = Folder:WaitForChild("LineStrobe1")
local L2 = Folder:WaitForChild("LineStrobe2")
local L3 = Folder:WaitForChild("LineStrobe3")
local L4 = Folder:WaitForChild("LineStrobe4")
local L5 = Folder:WaitForChild("LineStrobe5")
local L6 = Folder:WaitForChild("LineStrobe6")
while true do
for i,v in pairs(Folder:GetChildren()) do
for m,k in pairs(v:GetChildren()) do
for l,b in pairs(k:GetChildren()) do
if b.Material == Enum.Material.Neon then
if b.Name == "CL1" or b.Name == "CL3" or b.Name == "CL5" or b.Name == "CL7" or b.Name == "CL9" or b.Name == "CL11" then
print(b.Name)
b.SurfaceGui.Frame.Transparency = 1
elseif b.Name == "CL2" or b.Name == "CL4" or b.Name == "CL6" or b.Name == "CL7" or b.Name == "CL10" then
b.SurfaceGui.Frame.Transparency = .1
end
wait(.1)
if b.Name == "CL1" or b.Name == "CL3" or b.Name == "CL5" or b.Name == "CL7" or b.Name == "CL9" or b.Name == "CL11" then
b.SurfaceGui.Frame.Transparency = .1
elseif b.Name == "CL2" or b.Name == "CL4" or b.Name == "CL6" or b.Name == "CL7" or b.Name == "CL10" then
b.SurfaceGui.Frame.Transparency = 1
end
end
end
end
end
end
Fixed: Changed location of wait (and changed to get descendants but that part is irrelevant).
local Folder = workspace:WaitForChild("LineStobes")
while wait(1) do
for i,b in pairs(Folder:GetDescendants()) do
if b.Name == "CL1" or b.Name == "CL3" or b.Name == "CL5" or b.Name == "CL7" or b.Name == "CL9" or b.Name == "CL11" then
b.SurfaceGui.Frame.Transparency = .1
elseif b.Name == "CL2" or b.Name == "CL4" or b.Name == "CL6" or b.Name == "CL8" or b.Name == "CL10" then
b.SurfaceGui.Frame.Transparency = 1
end
end
wait(1)
for i,b in pairs(Folder:GetDescendants()) do
if b.Name == "CL1" or b.Name == "CL3" or b.Name == "CL5" or b.Name == "CL7" or b.Name == "CL9" or b.Name == "CL11" then
b.SurfaceGui.Frame.Transparency = 1
elseif b.Name == "CL2" or b.Name == "CL4" or b.Name == "CL6" or b.Name == "CL8" or b.Name == "CL10" then
b.SurfaceGui.Frame.Transparency = .1
end
end
end
You can capture the numbers from the names by using string.match and converting it to a number using tonumber.
local number = tonumber(string.matchGUI.Name, "%d+")
You can optionally just loop through all numbers if you know how many objects there are and turn them into a name to search for.
for number = 1,6 do
local GUI = k["CL"..number]
end
You can figure out whether the number is odd or even by using the modulus operation (%), aka remainder operation.
if number % 2 == 0 then
-- number is even since dividing by 2 on it gives a remainder of 0
else
-- number is odd
end
Putting it all together:
for i,b in pairs(Folder:GetDescendants()) do
local number = tonumber(string.match(b.Name, "%d+"))
if number % 2 == 1 then -- if number is odd
b.SurfaceGui.Frame.Transparency = .1
else -- if number is even
b.SurfaceGui.Frame.Transparency = 1
end
end
local Odds = {"CL1", "CL3", "CL5", "CL7", "CL9", "CL11"}
local Evens = {"CL2", "CL4", "CL6", "CL8", "CL10"}
local function Toggle(one, two)
for _, b in pairs(Folder:GetDescendants()) do
if table.find(Odds, b.Name) then b.SurfaceGui.Frame.Transparency = one end
if table.find(Evens, b.Name) then b.SurfaceGui.Frame.Transparency = two end
end
end
while true do
Toggle(.1, 1) task.wait(1)
Toggle(1, .1) task.wait(1)
end