So basically my idea is to make an oxygen bar but the catch is that it’s not just a simple frame bar, but in a form of 3 bubbles. The problem is that I’ve no idea how to script it so it’ll make each bubble disappear progressively while the oxygen goes down. If you’ve got any idea of the best method or any good alternatives I’ll be grateful. Thanks in advance.
Here’s a quick screenshot of how the bubble ui looks like:
Now we will need to get an array with the bubbles inside of them. Either use :GetChildren() or list them like so:
local bubbles = {
[1] = script.Parent:WaitForChild("Bubble1"), -- fix all the paths
[2] = script.Parent:WaitForChild("Bubble2"),
[3] = script.Parent:WaitForChild("Bubble3"),
}
Now Bubble1 will first expire and then the rest and so on.
Now let’s make a quick plan so we know what will happen:
If we only had one bubble we would use:
Basically the number 2 stands for the amount of bubbles, maxOx/2 is the Oxygen every bubble is worth.
To make this work for any script do the following every time you want to update the oxygen:
local amnt = #bubbles -- how many bubbles we got
local oxPerBubble = maxOx/amnt -- maxOx per bubble
-- Use this every time your oxygen changes:
for i, bubble in pairs(bubbles)
bubble.Transparency = 1 - (ox - oxPerBubble*(i-1))/oxPerBubble
end