Trying to make a Custom Bubble Chat Color for specific players

Hello there!

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a custom Bubble Chat background and text color3 for the names of the players that will be specified in the script.

  2. What is the issue? Include screenshots / videos if possible!
    Well the issue is that when i try to do it on myself it works but when i try to put the name of an another player such as “Player1” the script tells me that he doesn’t exist A.K.A “(PlayerName) isn’t a valid member of Players” and I have tried to fix that by putting an else if the statement is false but it still doesn’t fix it… it would be nice if someone can help me I just want to at least know what I am supposed to do because I am confused as to how to make this work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking this up online but I couldn’t find any results.

The part of "BubbleChat" local script part that i'm editing (it works if I put my own name but it doesn't if I put anyone else's name) this is obviously not the entire script
function createChatBubbleMain(filePrefix, sliceRect)
	local chatBubbleMain = Instance.new("ImageLabel")
	chatBubbleMain.Name = "ChatBubble"
	chatBubbleMain.ScaleType = Enum.ScaleType.Slice
	chatBubbleMain.SliceCenter = sliceRect
	chatBubbleMain.Image = "rbxasset://textures/" .. tostring(filePrefix) .. ".png"
	if game.Players.Nerkonl then
		chatBubbleMain.ImageColor3 = Color3.fromRGB(0,0,0)
	elseif game.Players.Nerkonl == nil then
		chatBubbleMain.ImageColor3 = Color3.fromRGB(255,255,255)
	end
	chatBubbleMain.BackgroundTransparency = 1
	chatBubbleMain.BorderSizePixel = 0
	chatBubbleMain.Size = UDim2.new(1.0, 0, 1.0, 0)
	chatBubbleMain.Position = UDim2.new(0,0,0,0)

	return chatBubbleMain
end

function createChatBubbleTail(position, size)
	local chatBubbleTail = Instance.new("ImageLabel")
	chatBubbleTail.Name = "ChatBubbleTail"
	chatBubbleTail.Image = "rbxasset://textures/ui/dialog_tail.png"
	if game.Players.Nerkonl then
		chatBubbleTail.ImageColor3 = Color3.fromRGB(0,0,0)
	elseif game.Players.Nerkonl == nil then
		chatBubbleTail.ImageColor3 = Color3.fromRGB(255,255,255)
	end
	chatBubbleTail.BackgroundTransparency = 1
	chatBubbleTail.BorderSizePixel = 0
	chatBubbleTail.Position = position
	chatBubbleTail.Size = size

	return chatBubbleTail	
end
1 Like

You could use the if statement and specify the player’s name and then just change the color of the char bubble, like this:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Name = "TestUsername"

if Player.Name == Name then do
   -- // make the chat bubble colour diffrent
end)

Hello.
You are getting an error because if the scripts fails to index “Nerkonl” (or any other name) inside game.Players, it will automatically error. Thus, the if statement will always error when the condition isn’t met.

if game.Players.Nerkonl then -- if the script doesn't find any child named "Nerkonl" it will error
	chatBubbleMain.ImageColor3 = Color3.fromRGB(0,0,0)
elseif game.Players.Nerkonl == nil then
	chatBubbleMain.ImageColor3 = Color3.fromRGB(255,255,255)
end

There is already a built-in function in Roblox to check if an instance exists as a child: FindFirstChild()
If it exists, it will return that object. Otherwise, it will return nil.

if Players:FindFirstChild("Nerkonl") then -- if the script doesn't find any child named "Nerkonl" it will not error
	chatBubbleMain.ImageColor3 = Color3.fromRGB(0,0,0)
else -- when the object is nil,
	chatBubbleMain.ImageColor3 = Color3.fromRGB(255,255,255)
end

As @DaffyDavinko suggested, I’d use local Players = game:GetService("Players") so the script isn’t too repetitive. Another good practice would be to store the Color3 values in a variable, so it is easier for you to change that value, and it is more efficient than calling Color3.fromRBG every time your functions are called.


I recommend you take a look at this custom bubble chat made by @Alphexus. It can give you ideas on improving your scripts.

1 Like

Wait you actually fixed it, wow I didn’t think of doing that… lol 681766487492657153

tysm anyways your a legend.

2 Likes

Thanks for explaining it, that’s nice.

1 Like