Hi! So, I wanted to make a rainbow bubble chat in my game (changes color every 2 seconds), and I made it so that it loops through a table of colors and every two second, sets the color to that. Here is the code:
local colors = {
["1"] = Color3.new(0.666667, 0.333333, 1),
["2"] = Color3.new(0, 0, 1),
["3"] = Color3.new(0.333333, 0.666667, 1),
["4"] = Color3.new(0.333333, 1, 0.498039),
["5"] = Color3.new(1, 1, 0),
["6"] = Color3.new(1, 0.666667, 0),
["7"] = Color3.new(1, 0, 0)
}
local Chosen = 1
local color
while wait(2) do
if Chosen ~= 7 then
color = colors[tostring(Chosen)]
Chosen = Chosen + 1
else
Chosen = 1
color = colors[tostring(Chosen)]
end
game:GetService("Chat"):SetBubbleChatSettings({
BackgroundColor3 = color,
VerticalStudsOffset = 1.5
})
print(Chosen)
end
If you noticed the print at the bottom, for some reason, it stops printing anything after the variable “Chosen” gets to 4. It would print 1, 2, 3, 4 and then nothing. Does anyone know what the problem is? Thank you!
PS: The script is in a local script inside of StarterGUI and there is no actual issue with the bubble chat color changing. The only problem is that the variable “Chosen” stops at 4.
2- Why not use a for or for ipairs loop for your script? You wouldn’t have to keep track of a global and keep reassigning values.
while true do
for i = 1,7 do -- you could also do for i,v in ipairs(colors) do
game:GetService("Chat"):SetBubbleChatSettings({
BackgroundColor3 = colors[i], -- you could also do v if you're doing the ipairs option
VerticalStudsOffset = 1.5
})
wait(2)
end
end
The exact same thing happens as before. I added a print statement inside the for loop to print the colors[i] and noticed that some numbers printed 4 times, but then stopped. This is very weird because even before, the variable “Chosen” kept stopping at 4 and now, it stops at the 4th index of the table, which in my table is green.
Ok sure! You can just put the script inside a localscript inside of a screenGUI. Also, make sure you have the setting BubbleChatEnabled set to true. You can find it in the properties of Chat. Thanks!
local colors = {
Color3.new(0.666667, 0.333333, 1),
Color3.new(0, 0, 1),
Color3.new(0.333333, 0.666667, 1),
Color3.new(0.333333, 1, 0.498039),
Color3.new(1, 1, 0),
Color3.new(1, 0.666667, 0),
Color3.new(1, 0, 0)
}
while true do
for i = 1,7 do -- you could also do for i,v in ipairs(colors) do
game:GetService("Chat"):SetBubbleChatSettings({
BackgroundColor3 = colors[i], -- you could also do v if you're doing the ipairs option
VerticalStudsOffset = 1.5
})
wait(2)
print('bubble chat')
end
end
It works now! Thank you so much! I just wanted to ask one last thing, is it possible for the color to (in a way) tween into the next color? Right now, it just switches between each color in a robotic manner. Is there any way to make it fade from one color to the next? Thank you so much!
I know it isn’t exactly a problem but I recommend using Color3.fromRGB, as it can help you learn how certain colors mix and how different saturations and hues look :DD
Color3.fromRGB and Color3.new are the same thing pretty much. C3.new just takes the R, G and B values and divides them by 255 (or vice versa, probably for memory).
So basically,
Color3.new(0.5,0.5,0.5)
-- and
Color3.fromRGB(51,51,51)