Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to change image transparency of multiple labels at once?

Asked by 2 years ago

How can I change the transparency of 6 different image labels all at the same time?

Currently I have them all defined like this:

local classBorders = {script.Parent.Parent.BDs.classBDx, script.Parent.Parent.BDs.classBDx1, script.Parent.Parent.BDs.classBDy, script.Parent.Parent.BDs.classBDy1, script.Parent.Parent.BDs.classBDz, script.Parent.Parent.BDs.classBDz1}

However when I try change the transparency it won't work.

0
I recommending studying the following article. It will help solidify your knowledge on tables and proper iteration**. https://developer.roblox.com/en-us/articles/Table Ziffixture 6913 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

We can use something called for loops for this. for loops lets you run a command or group of commands at a set number of times, or we can use it to iterate through tables/arrays. It should look something like this:

local Alphabet = {"A", "B", "C", "D"} -- Your table here

for i,v in pairs(Alphabet) do -- You can name i and v anything you want. i stands for index and v stands for value
    print(i .. " | " .. v)
    task.wait(1) -- Just some extra stuff, and task.wait is exclusive to Roblox, Lua doesn't officially have this syntax.
    print(v .. " is in the alphabet!")
end

Output:

1 | A

2 | B

3 | C

4 | D

Script waits for 1 second

A is in the alphabet!

B is in the alphabet!

C is in the alphabet!

D is in the alphabet!

And you can play around with this, like changing all of the parent's children's property. (e.g changing every x's children transparency to 0.5)

This, of course isn't a complete tutorial about for loops. You can see more in the DevForum link @Ziffixture sent in the comment section.

Happy scripting!

0
Thank you! SilentKiller5557 8 — 2y
Ad

Answer this question