Bubble chat issue

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! :grinning:

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.

A few things:

1- You don’t have to manually define your indexes. It should work as normal if you did something like

local colors = {
    Color3.new(2/3, 1/3, 1);
    Color3.new(0, 0, 1);
-- etc
}

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
1 Like

Let me try that out, thank you so much!

1 Like

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.

That’s weird, I’ll try it out myself and get back to 'ya.

1 Like

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!

1 Like

Forgot to put this before, this is my colors table:

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.333333, 0);
	Color3.new(1, 0, 0)
	-- etc
}
```
1 Like

Strange, it works for me.

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

Put it in StarterPlayer → StarterPlayerScripts

1 Like

Oh, starterplayerscripts? Let me try that, thank you!

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

Cheers!

1 Like

Thank you for the suggestion, I will keep that in mind!

1 Like

Yeah, you can use TweenService for that, which was I was gonna suggest haha.

Script:

local tweenService = game:GetService('TweenService')
local number = Instance.new('NumberValue')

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)
}

local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear)

number.Changed:Connect(function()
	game:GetService("Chat"):SetBubbleChatSettings({
		BackgroundColor3 = Color3.fromHSV(number.Value, 1, 1),
		VerticalStudsOffset = 1.5
	})
end)

while true do
	local tween = tweenService:Create(number, tweenInfo, {Value = 1})
	tween:Play()
	tween.Completed:Wait()
	number.Value = 0
end
1 Like

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)

are nearly the same thing.

1 Like

I know they are the same thing but RGB is more commonly used in a 0-255 manor. I just feel it’s better practice.

2 Likes

Thank you! This works amazingly! You helped me a lot!

1 Like