So, I recently found a solution to my color changing problem with ImageLabels. No disrespect to anyone who gave their suggestions, but I’m not an expert scripter, so I couldn’t figure it out for the life of me. Anyway, I am now trying to find a way to do the following: highlight ImageLabels that have the same ImageColor3 and have them change ImageTransparencies at the same time, via a GUI panel.
Going back to Blockbusters, whenever a team was close to finishing a path, their appropriate colors would flash on the game board. The same applied when they made a complete path from one side to the other. The cheap alternative would be to flash the white and blue spaces on the outside of the board, but I want to try the former before doing the latter.
As before, the panel would be connected to three other screens (parts with SurfaceGuis) that display the game board.
local screenGui = script.Parent
for _, image in ipairs(screenGui:GetDescendants()) do --change to GetChildren() if necessary
if image:IsA("ImageLabel") then
if image.ImageColor3 == Color3.new(0, 0, 0) then --black for example
image.Transparency = 1 --make invisible
end
end
end
It does work, but not in the way I envisioned it. I have a TextButton and when I click that button, I want the script inside it to activate the ImageLabel transparencies for those with the same colors. However, they need to work with the ImageLabels that already turned that color, not the ones with them preset. I have a panel that changes the hexagon’s colors.
local gui = script:FindFirstAncestorWhichIsA("ScreenGui")
local button = script.Parent
button.MouseButton1Click:Connect(function()
for _, image in ipairs(gui:GetDescendants()) do
if image:IsA("ImageLabel") then
if button.BackgroundColor3 == image.ImageColor3 then
image.Transparency = 0
end
end
end
end)
For the behavior that you described (in the latter part of your response) you’ll need to differentiate between and store which images have had their colors changed as opposed to the images which already had their colors set.
local gui = script:FindFirstAncestorWhichIsA("ScreenGui")
local button = script.Parent
local updatedImages = {}
local function createImageColorSignals()
for _, image in ipairs(gui:GetChildren()) do
if image:IsA("ImageLabel") then
image:GetPropertyChangedSignal("ImageColor3"):Connect(function()
table.insert(updatedImages, image)
end)
end
end
end
createImageColorSignals()
button.MouseButton1Click:Connect(function()
for _, image in ipairs(updatedImages) do
if button.BackgroundColor3 == image.ImageColor3 then
image.Transparency = 0
end
end
end)
for _, image in ipairs(gui:GetDescendants()) do
if image.Name:match("^Space") then
--do specific action for images where name starts with "Space"
end
end
Alright. I was also planning on doing a looping of the flash in the script, but I’m not sure how to accomplish that. I can’t do a separate script for each ImageLabel, because that would be too complicated and the ImageButton script might not pick that up.
That loop would be for each ImageLabel instance, the loop iterates for 10 cycles, toggling the transparency between 0 and 1 with a 0.1 second interval between each state change. Because you have multiple ImageLabels which need changing simultaneously you’ll need to create additional threads (so that the main thread isn’t yielded).
task.spawn(function()
for i = 1, 10 do
task.wait(0.1)
image.Transparency = i % 2
end
end)
Also the numbers used were just an example, you may wish to have the flashing occur more frequently, for a longer duration, more interval between each flash etc.
% is the modulo operator in Lua, it returns the remainder when dividing the first value by the second, so in this case when i is 1, 1 % 2 returns 1 as 1 is the remainder (1 cannot go into 2), on the second time round i is 2 and 2 divided by 2 has a remainder of 0.
local gui = script:FindFirstAncestorWhichIsA("ScreenGui")
local button = script.Parent
local updatedImages = {}
local function createImageColorSignals()
for _, image in ipairs(gui:GetDescendants()) do
if image.Name:match("^Space") then
--do specific action for images where name starts with "Space"
end
end
end
createImageColorSignals()
button.MouseButton1Click:Connect(function()
for _, image in ipairs(updatedImages) do
if button.BackgroundColor3 == image.ImageColor3 then
image.Transparency = 0
end
end
end)