#How do I change a player's chat colour with a server-side script?

1 messages · Page 1 of 1 (latest)

slow merlin
#

I'm trying to change a player's chat bubble text colour with a server-side script. I have already scripted a GUI which fires the player's chosen colour to the server, but I don't know how to proceed on from here. For example I'd like all other people to see that my text colour is red, but for them, it remains their chosen colour.

Here's what I've scripted so far for the server script. Can anyone help?

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChangeChatColour = ReplicatedStorage.Remotes:WaitForChild("ChangeChatColour")

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")


--Change player's chat colour: others remain unaffected but can see it
ChangeChatColour.OnServerEvent:Connect(function(newColour)
    
    
end)
worldly geode
#

”I’ve scripted” Nice chatgpt

slow merlin
#

I didn't use chat GPT for this at all
Is there any way you could help?

neat needleBOT
#

studio** You are now Level 2! **studio

slow merlin
cinder temple
slow merlin
# cinder temple Do you want to change the player's *window* chat color or *bubble* chat color? B...

The bubble chat colour is what I want to change.
I've tried writing a few lines to apply the colour to the message, but it doesn't seem to change.

It at least recognises that the colour has been selected in the console, though.

btn.MouseButton1Click:Connect(function()
    -- Always get the current colour when the button is clicked
    local newColour = displayColour.ImageColor3
    print("Selected TextChat Colour: ", newColour)
        
    --ChangeChatColour:FireServer(newColour)
    
    TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
        if message.TextSource then
            local bubbleProperties = Instance.new("BubbleChatMessageProperties")
            local player = Players:GetPlayerByUserId(message.TextSource.UserId)
            
            if player:GetAttribute(player.UserId) then
                bubbleProperties.TextColor3 = newColour
                return bubbleProperties
            end    
        end
    end
end)
cinder temple
#

Try placing the OnBubbleAdded outside of the MouseButton1Click and store the new color in a field variable instead, then use that in the OnBubble Added

#
local currentColor = -- someColor

btn.MouseButton1Click:Connect(...) -- set currentColor

TextChatService.OnBubbleAdded = ... -- use currentColor
#

If this method somehow works, you have another underlying problem; this won't be replicated to other clients, meaning only the local player will be able to see that their chat bubble is a different color. Other players would only see the default one on their screens.

slow merlin
# cinder temple ```lua local currentColor = -- someColor btn.MouseButton1Click:Connect(...) -- ...

I've followed your method as best as I can, but I get the error:

"Error occurred while calling TextChatService.OnBubbleAdded: Error occurred while calling TextChatService.OnBubbleAdded: Unable to assign property TextColor3. Color3 expected, got nil"

btn.MouseButton1Click:Connect(function()
    -- Always get the current colour when the button is clicked
    local newColour = displayColour.ImageColor3
    print("Selected TextChat Colour: ", newColour)
    
end)

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance, newColour)
    if message.TextSource then
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        
        bubbleProperties.TextColor3 = newColour
        return bubbleProperties
    end
end
cinder temple
#

You're missing the first line. local currentColor

Place that outside, before the MouseButton1Click.

#

It's that one that you should set the new color to, and that one you should use as the TextColor3 value in OnBubbleAdded

slow merlin
# cinder temple You're missing the first line. `local currentColor` Place that outside, before ...

Sorry, I forgot to mention that I had already done that, but I still get the "Color3 expected, got nil" error

local displayColour = script.Parent.Parent.Parent:WaitForChild("ColourDisplay")

btn.MouseButton1Click:Connect(function()
    -- Always get the current colour when the button is clicked
    local newColour = displayColour.ImageColor3
    print("Selected TextChat Colour: ", newColour)
    
end)

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance, newColour)
    if message.TextSource then
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        
        bubbleProperties.TextColor3 = newColour
        return bubbleProperties
    end
end
cinder temple
#

Let me re-iterate:

It's displayColour you should set the new color to, and displayColour you should use as the TextColor3 value in OnBubbleAdded

#

Instead of newColour, assign the color to displayColour, your field variable.

#

And instead of newColour, use displayColour as the value for TextColor3 in OnBubbleAdded

slow merlin
# cinder temple And instead of newColour, use **displayColour** as the value for TextColor3 in `...

Ok, I think I've managed to do something right.
I'm not sure if it's what you wanted me to do, but...

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        local newColour = displayColour.ImageColor3 

        bubbleProperties.TextColor3 = newColour
        return bubbleProperties
    end
end

The colour of the text changes now.

#

Sorry if I've annoyed you in anyway with my lack of skill here, though.

#

Now I just need to find a way to fire it to the server so everyone can see it.

cinder temple
#

It's totally fine, and dw I'm not annoyed. This is a learning environment and I just don't wanna outright give you the answer so you could learn.

That's not the way I thought of, but if it works then yea that's great.

cinder temple
#

You're gonna need a whole different system. Basically, off the top of my head, here's what you'll need to do:

  • Store the player colors in the server, maybe in an array or something, like this:
local playerColors = {}
  • Then, when a player changes their color, use a RemoteEvent to tell the server "Hey, this player changed their color. Add them to the playerColors list."
chatColorChangeEvent.OnServerEvent:Connect(function(player, chatColor)
    playerColors[player.UserId] = chatColor -- Let's use userId instead of Player to make it cleaner
end)
  • Then, in your OnBubbleAdded (which is still in a local client), we get the player's color from the server. So we need to create a RemoteFunction to get the player's color.
-- In the serverscript
GetPlayerChatColorFunction.OnServerInvoke = function(requestor, player)
-- requestor is the player who sent the function, player is a parameter
    return playerColors[player.UserId] -- We'll return the player's custom color    
end

-- In the localscript
TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local chatColor = GetPlayerChatColorFunction:InvokeServer(player) or Color3.fromRGB(255, 255, 255) -- we get the player's color or WHITE if player has no custom color

        local bubbleProperties = Instance.new("BubbleChatMessageProperties")

        bubbleProperties.TextColor3 = chatColor
        return bubbleProperties
    end
end
#

I made something similar a while back, and this is more or less a simplified version of what I came up with

slow merlin
#

Alright, thanks a bunch
I'll come back to you with my results

neat needleBOT
#

studio** You are now Level 3! **studio

slow merlin
# cinder temple You're gonna need a whole different system. Basically, off the top of my head, h...

Ok, I've done a few things...
First, I've gone and stored the player ID and colours in a table in the server. I've reported it to the output so I'd see what was sent.

Example: 102859680 stored colour 1, 0, 0.684365 - Server - ChangeBubbleTextColour:13

[Server Script]

local changeColourEvent = ReplicatedStorage.Remotes:WaitForChild("ChangeChatColour")

-- Store colours in a table and report to the server
changeColourEvent.OnServerEvent:Connect(function(player, newColour)
    playerColours[player.UserId] = newColour
    print(player.UserId, "stored colour", newColour)
end)

Then, in the local script, I tried to follow what you did, but I got the error: Error occurred while calling TextChatService.OnBubbleAdded: InvokeServer is not a valid member of RemoteEvent "ReplicatedStorage.Remotes.GetPlayerChatColour" - Client

[Local Script]

local getColourEvent = ReplicatedStorage.Remotes:WaitForChild("GetPlayerChatColour")

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local newColour = getColourEvent:InvokeServer(player) or Color3.fromRGB(255, 255, 255) -- we get the player's color or WHITE if player has no custom color
        
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")


        bubbleProperties.TextColor3 = newColour
        return bubbleProperties
    end
end
cinder temple
#

You're actually doing great, good job

The reason for your error: You're using RemoteEvent when it should be a RemoteFunction

#

When we use RemoteFunction, the server can return something. In our case, we use RemoteFunction to basically tell the server "Hey, give me the custom color of this player". Then the server returns it to us. We can't do this in a RemoteEvent (we can't return anything in events)

slow merlin
#

Ah, ok. So I should change my RemoteEvent "GetPlayerChatColour" to a RemoteFunction.

cinder temple
#

Correct 👍

slow merlin
#

Alright, I no longer get the error. Just testing now...

#

And it works!!

cinder temple
#

Nice!! Congrats 😄

slow merlin
#

Thank you so much for your time and help. Is there anyway I can repay you?

cinder temple
#

Haha it's fine, just happy to help 🙂

slow merlin
#

Alright, got it. Last question, I plan to do the same for the bubble background colour. Aside from making the obvious changes (TextColor3 to BackgroundColor3) is there anything else that I should keep in mind?

cinder temple
#

Hmm, just a tip.. You can return tables instead of singular variables in RemoteFunctions, so you could send something like this:

{
    TextColor = Color3,
    BackgroundColor = Color3,
    Bold = true,
    FontFamily = Enum.Font.Something
   -- etc
}

And with this, you can simply do something like this in your OnBubbleAdded:

local customization = GetPlayerChatBubbleCustomization:Invo...

if customization.BackgroundColor then
    -- add bg color 
end

if customization.FontFamily then
    -- change font family
end
#

And dont forget to refer to the docs you sent so you know what you can customize. You can be very creative with it

#

Here's a quick ss of what I did a while back, I managed to add custom images to it too 😄

slow merlin
#

Looking cool! I think I should try to do that in the future instead of now, I don't wanna waste any more of your time here

cinder temple
#

Alright lol. Have fun scripting

slow merlin
#

Thanks once again!

#

This is the GUI I've been working on, incase you were ever interested.

cinder temple
#

Oh nice, that's a good project for learning

slow merlin
cinder temple
slow merlin
#

Well for starters, I made BG Colour variants of what I did for the text, I changed a few variables in both the server script and local script

#

[Local Script, in button]

local btn = script.Parent

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChangeBubbleColour = ReplicatedStorage.Remotes:WaitForChild("ChangeBubbleColour")

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local displayColour = script.Parent.Parent.Parent:WaitForChild("ColourDisplay")


btn.MouseButton1Click:Connect(function()
    -- Always get the current colour when the button is clicked
    local newTextBubbleColour = displayColour.ImageColor3
    print("Selected TextBubble Colour: ", newTextBubbleColour)
    ChangeBubbleColour:FireServer(newTextBubbleColour)
    
end)
local getBubbleColourEvent = ReplicatedStorage.Remotes:WaitForChild("GetPlayerBubbleColour")

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local newTextBubbleColour = getBubbleColourEvent:InvokeServer(player)
        
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")


        bubbleProperties.BackgroundColor3 = newTextBubbleColour
        return bubbleProperties
    end
end
#

[Server Script Part 1]

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")

-- CHANGING AND GETTING CHAT COLOURS --
local changeChatColourEvent = ReplicatedStorage.Remotes:WaitForChild("ChangeChatColour")
local getChatColourEvent = ReplicatedStorage.Remotes:WaitForChild("GetPlayerChatColour")

-- CHANGING AND GETTING BUBBLE COLOURS --
local changeBubbleColourEvent = ReplicatedStorage.Remotes:WaitForChild("ChangeBubbleColour")
local getBubbleColourEvent = ReplicatedStorage.Remotes:WaitForChild("GetPlayerBubbleColour")

-- STORING COLOURS --
local playerTextColours = {}
local playerBubbleColours = {}

-- Store colours in a table and report to the server
changeChatColourEvent.OnServerEvent:Connect(function(player, newColour)
    playerTextColours[player.UserId] = newColour
    print(player.UserId, "stored text colour", newColour)
end)

changeBubbleColourEvent.OnServerEvent:Connect(function(player, newColour)
    playerBubbleColours[player.UserId] = newColour
    print(player.UserId, "stored bubble colour", newColour)
end)

-- Invoke the function to the server and return the colour to the client
getChatColourEvent.OnServerInvoke = function(requestor, player)
    return playerTextColours[player.UserId] -- Return the player's custom colour    
end

getBubbleColourEvent.OnServerInvoke = function(requestor, player)
    return playerBubbleColours[player.UserId]    
end
#

[ServerScript Part 2]

TextChatService.OnBubbleAdded = function(message, adornee)
    if message.TextSource then    
        
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        local userId = message.TextSource.UserId
        if playerTextColours[userId] then
            bubbleProperties.TextColor3 = playerTextColours[userId]
        else
            bubbleProperties.TextColor3 = Color3.fromRGB(57, 59, 61)
        end
        
        if playerTextColours[userId] then
            bubbleProperties.BackgroundColor3 = playerTextColours[userId]
        else
            bubbleProperties.BackgroundColor3 = Color3.fromRGB(250, 250, 250)
        end
        
        return bubbleProperties
    end
end
#

What I get from this, is that the Text works as normal, however, the bubble doesnt change.

cinder temple
#

To simplify, OnBubbleAdded is basically a variable. Currently, what you're doing is equivalent to this:

local OnBubbleAdded

OnBubbleAdded = Value1

-- Then in another script
OnBubbleAdded = Value2

-- So now, when roblox uses the OnBubbleAdded function, it'll of course only output/use Value2, since that's what it's currently set to
print(OnBubbleAdded) -- Value2
slow merlin
#

I have two buttons, one for the text and the background. How can I make sure the bubble colour isn't changed at the same time at the text colour?

cinder temple
#

Return a table with optional entries, like..

{
   TextColor: Color3?,
   BackgroundColor: Color3?
}
#

And in your OnBubbleAdded, simply check if that entry exists.

if configuration.TextColor then
    -- set TextColor
end

if configuration.BackgroundColor then
    -- set BackgroundColor
end
#

Now all that's left is how you save the table. You can add or remove from the table whichever values you want

neat needleBOT
#

studio** You are now Level 7! **studio

slow merlin
slow merlin
cinder temple
#

I think you're getting it mixed up

#

What about this.. What do you use to store the TextColor in the server? What's the array

#

I'm guessing it's something like..

local playerTextColors = {}

In that case, replace that with the table.

cinder temple
slow merlin
#
-- STORING COLOURS --
local playerTextColours = {}
local playerBubbleColours = {}

This is what I currently use

neat needleBOT
#

studio** You are now Level 4! **studio

slow merlin
#

I was thinking of maybe setting up a table like this:
{playerID, textCol, bubbleCol}

cinder temple
#

Where the key is the UserId

#

Now, same as before, return that when the client requests for a player's chatCustomization

GetChatCustomization.OnServerInvoke = function(requestor, player)
    return playerChatCustomization[player.UserId]
end
slow merlin
#

Im guessing that goes in the OnBubbleAdded?

#

On both the client and the server.

cinder temple
cinder temple
#

No, that's your storage in server

#

When a player presses a button or chooses a color you save it to there

#

Here's a quick outline:

  • Player chooses a color, be it textColor or backgroundColor.

  • Use RemoteEvent to tell the server "Hey, player wants to set their textColor to color", then server saves it to playerChatCustomization

  • Then, in your OnBubbleAdded, get the customization of the player who's chat bubble belongs to by calling a RemoteFunction to the server, then use that.

slow merlin
#

I see, let me try to repeat that in what I understand.

#
  1. The player chooses a colour, and it is fired to the server via remote event.
btn.MouseButton1Click:Connect(function()
    -- Always get the current colour when the button is clicked
    local newColour = displayColour.ImageColor3
    print("Selected TextChat Colour: ", newColour)
    ChangeChatColour:FireServer(newColour)
    
end)

That part I understand

#

I mainly don't understand the saving part.

slow merlin
cinder temple
#

Hmm, genuine question, do you understand how dicts work?

cinder temple
# slow merlin ```lua local player = game.Players.LocalPlayer -- STORING COLOURS -- local cust...

Basically, customPlayerChat is a dictionary, in short dict, where it has a key-value pair as opposed to the normal array's indexes table.

In customPlayerChat, we're just setting another dict as a value to the first one. (also called as Nested Dicts)

local customPlayerChat = {}

-- To add a customization, do this:
customPlayerChat[userId] = {
   TextColour = newTextCol,
   BackgroundColour = newBGCol
}
#

The Key is the user id, and the value is another dict, which is...

{
   TextColour = newTextCol,
   BackgroundColour = newBGCol
}

So now, if you get the value of customPlayerChat, you're gonna get that ^.

cinder temple
slow merlin
# cinder temple You put the customPlayerChat variable itself in the field, meaning not inside an...

I've attempted to use this new system, does this look right to you?


local player = game.Players.LocalPlayer

-- STORING COLOURS --
local customPlayerChat = {}


-- Store colours in a table and report to the server
changeChatColourEvent.OnServerEvent:Connect(function(player, newTextCol)
    customPlayerChat[player.UserId] = newTextCol
    print(player.UserId, "stored text colour", newTextCol)
end)

-- Invoke the function to the server and return the colour to the client
getChatColourEvent.OnServerInvoke = function(requestor, player)
    return customPlayerChat[player.UserId] -- Return the player's custom colour    
end

TextChatService.OnBubbleAdded = function(message, adornee)
    if message.TextSource then    
        -- Text Colours --
        -- Set up variables
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        local userId = message.TextSource.UserId
        
        
        if customPlayerChat.newTextCol[userId] then
            bubbleProperties.TextColor3 = customPlayerChat.newTextCol[userId]
        end
        return bubbleProperties
        
    end
end
cinder temple
#

Instead of storing the newTextCol itself, store it in a table and store that to customPlayerChat

#
changeChatColourEvent.OnServerEvent:Connect(function(player, newTextCol)
    customPlayerChat[player.UserId] = {
        TextColor: newTextCol
    }
    print(player.UserId, "stored text colour", newTextCol)
end)
#

But actually, this overrides the current value of the player's entry in customPlayerChat... We only need to update the saved entry rather than replace it entirely, so let's do this:

#
changeChatColourEvent.OnServerEvent:Connect(function(player, newTextCol)
    local playerChat = customPlayerChat[player.UserId] or {} -- We get the current entry of player in customPlayerChat, or output an empty list {} if there is none yet.
    
    playerChat.TextColor = newTextCol -- Update the TextColor field of playerChat

    customPlayerChat[player.UserId] = playerChat -- we set it back in customPlayerChat    

    print(player.UserId, "stored text colour", newTextCol)
end)
#

This allows you to add more fields to the customPlayerChat however many we want, meaning we can do the same with backgroundColor by copy and pasting the textColor function and modifying it like so...

changeBackgroundColourEvent.OnServerEvent:Connect(function(player, newBackgroundCol)
    local playerChat = customPlayerChat[player.UserId] or {} -- We get the current entry of player in customPlayerChat, or output an empty list {} if there is none yet.
    
    playerChat.BackgroundColor = newBackgroundCol-- Update the BackgroundColor field of playerChat

    customPlayerChat[player.UserId] = playerChat -- we set it back in customPlayerChat    

    print(player.UserId, "stored background colour", newBackgroundCol)
end)
slow merlin
# cinder temple This allows you to add more fields to the `customPlayerChat` however many we wan...

I see, I think I get it now. I believe this is the last part, trying to return the text colour. Does this seem right?

TextChatService.OnBubbleAdded = function(message, adornee)
    if message.TextSource then    
        -- Text Colours --
        -- Set up variables
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        local userId = message.TextSource.UserId
        
        
        if customPlayerChat[userId] then
            bubbleProperties.TextColor3 = customPlayerChat[userId]["TextColor"]
        end
        return bubbleProperties
        
    end
end
cinder temple
#

Then to check for backgroundColor, simply do the same:

if customPlayerChat[userId] then
    if customPlayerChat[userId]["TextColor"] then -- We check if this field exists. If it does, we set it.
        bubbleProperties.TextColor3 = customPlayerChat[userId]["TextColor"]
    end
    
    if customPlayerChat[userId]["BackgroundColor"] then -- We check if this field exists. If it does, we set it.
        bubbleProperties.TextColor3 = customPlayerChat[userId]["BackgroundColor"]
    end
end
#

Oh, wait.. You're missing the RemoteFunction. That's how you should get the customPlayerChat of the player, since the customPlayerChat storage is in the server

slow merlin
#

That must be why I get the error
"Error occurred while calling TextChatService.OnBubbleAdded: Unable to assign property TextColor3. Color3 expected, got table "

cinder temple
slow merlin
#

I think the problem lies here.

-- Store colours in a table and report to the server
changeChatColourEvent.OnServerEvent:Connect(function(player, newTextCol)
    local playerChat = customPlayerChat[player.UserId] or {} -- We get the current entry of player in customPlayerChat, or output an empty list {} if there is none yet.

    playerChat.TextColor = newTextCol -- Update the TextColor field of playerChat

    customPlayerChat[player.UserId] = playerChat -- we set it back in customPlayerChat    

    print(player.UserId, "stored text colour", newTextCol)
end)

-- Invoke the function to the server and return the colour to the client
getChatColourEvent.OnServerInvoke = function(requestor, player)
    return customPlayerChat[player.UserId] -- Return the player's custom colour    
end
#

I'm thinking that it's the playerChat.TextColor = newTextCol line

slow merlin
# cinder temple Hmm, probably. The error is basically saying "Hey, TextColor3 needs a Color3 val...

Unless it's here, I can't tell

--OnBubbleAdded in Server--
if customPlayerChat[userId] then
            if customPlayerChat[userId]["TextColor"] then -- We check if this field exists. If it does, we set it.
                bubbleProperties.TextColor3 = Color3.fromRGB(250, 250, 250)
            end
        end


--OnBubbleAdded in Client--
if customPlayerChat[userId] then
            if customPlayerChat[userId]["TextColor"] then -- We check if this field exists. If it does, we set it.
                bubbleProperties.TextColor3 = Color3.fromRGB(250, 250, 250)
            end
        end
cinder temple
slow merlin
#

Judging by the colours, somewhere in the client

cinder temple
#

Is there no other info? What about the text below that error?

cinder temple
slow merlin
#

I mean the colour at the side of the console
It doesn't say which line, though

cinder temple
#

What happens when you left click the error?

#

It should bring you directly to the line if you click it

slow merlin
#

Well, nothing
I'm hovering over the line and it says "Source not available"

cinder temple
#

Can you show your entire OnBubbleAdded function?

slow merlin
#
TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local newTextCol = getTextColourEvent:InvokeServer(player) or Color3.fromRGB(255, 255, 255) -- we get the player's color or WHITE if player has no custom color
        
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")


        bubbleProperties.TextColor3 = newTextCol
        return bubbleProperties
    else
        print("ERROR SETTING COLOUR! - CLIENT")
    end
end
cinder temple
#
local newTextCol = getTextColourEvent:InvokeServer(player) or Color3.fromRGB(255, 255, 255) -- we get the player's color or WHITE if player has no custom color

This is the reason. Remember, we are returning a table now when we invoke the RemoteFunction.

cinder temple
slow merlin
#

Ok, so would it be something like this?

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local newTextCol = getTextColourEvent:InvokeServer(customPlayerChat[userId]["TextColor"]) or Color3.fromRGB(255, 255, 255) -- we get the player's color or WHITE if player has no custom color
        
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")


        bubbleProperties.TextColor3 = newTextCol
        return bubbleProperties
    else
        print("ERROR SETTING COLOUR! - CLIENT")
    end
end
cinder temple
#

Think of InvokeServer as a normal function, except it's from client to server to client. Basically...


-- In your server...
someFunction.OnServerInvoked = function(player, param1, param2)
    return "Hello"
end

-- In your client...
print(someFunction:InvokeServer(param1, param2)) -- Outputs Hello



-- is the same as



-- Both in client...
local someFunction(param1, param2)
    return "Hello"
end

print(someFunction(param1, param2)) -- Outputs Hello
#

Hopefully that helps you understand how RemoteFunctions work

slow merlin
#

However, I do have a better understanding on how remote functions work

slow merlin
neat needleBOT
#

studio** You are now Level 5! **studio

cinder temple
#

We changed what we return in the RemoteFunction, right?

#

It's not a TextColor3 anymore, which is what your OnBubbleAdded is expecting.

#

Change how OnBubbleAdded uses the output of getTextColourEvent.

slow merlin
cinder temple
#

You're getting there, but kinda not too

I think you'll understand it better if you rename newTextCol to customPlayerChatTable

slow merlin
slow merlin
# cinder temple You're getting there, but kinda not too I think you'll understand it better if ...

Finally fixed it!

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local customPlayerChat = getTextColourEvent:InvokeServer(player) or Color3.fromRGB(57, 59, 61) -- we get the player's color or WHITE if player has no custom color
        local chatCol = customPlayerChat and customPlayerChat.TextColor or Color3.fromRGB(57, 59, 61)  -- Default to gray if nil
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")

        print(player, "is trying to set text colour", customPlayerChat)

        bubbleProperties.TextColor3 = chatCol
        return bubbleProperties
    else
        print("ERROR SETTING COLOUR! - CLIENT")
    end
end
#

It was this part that needed changing.

local customPlayerChat = getTextColourEvent:InvokeServer(player) or Color3.fromRGB(57, 59, 61) -- we get the player's color or WHITE if player has no custom color
        local chatCol = customPlayerChat and customPlayerChat.TextColor or Color3.fromRGB(57, 59, 61)  -- Default to gray if nil
#

It still doesn't work for bubble colours, though. I practically copied and pasted it but it didn't do anything

#

It's probably something to do with overwriting.

slow merlin
#

Ok so I'll put everything together:

  • Text colours do work
  • Bubble Colours don't work
  • I can remove the entire "OnBubbleAdded" in the server and it still works since OnBubbleAdded can only be used in the client
  • However, if I move the Text OnBubbleAdded in the client, BackgroundColors will work.

I think something is being overwritten by accident like I said before

cinder temple
#

Sorry, I was away yesterday

cinder temple
#

The only wrong thing is you still have a default value for customPlayerChat and it's even the wrong type.. You can remove that

cinder temple
#
local chatCol = customPlayerChat and customPlayerChat.TextColor or Color3.fromRGB(57, 59, 61)  -- Default to gray if nil
local backgroundCol = customPlayerChat and customPlayerChat.BackgroundColor or Color3.fromRGB(255, 255, 255)  -- Default to white if nil
slow merlin
# cinder temple What exactly did you copy paste? It should work fine if you copy pasted the `cha...

I copy pasted the text colour lines, and made sure everything applied to the background colour instead.

TextChatService.OnBubbleAdded = function(message: TextChatMessage, adornee: Instance)
    if message.TextSource then
        
        local player = Players:GetPlayerByUserId(message.TextSource.UserId)
        local customPlayerChat = getBubbleColourEvent:InvokeServer(player) or Color3.fromRGB(195, 195, 195)
        local bubbleCol = customPlayerChat and customPlayerChat.BackgroundColor or Color3.fromRGB(12, 195, 195)
        local bubbleProperties = Instance.new("BubbleChatMessageProperties")
        
        print("Received background colour: ", bubbleCol)
        bubbleProperties.BackgroundColor3 = bubbleCol
        return bubbleProperties
    end
end
cinder temple
#

Did you copy paste the entire OnBubbleAdded line??

neat needleBOT
#

studio** You are now Level 8! **studio

slow merlin
#

Yep
(I know images aren't the right way to send them but here they are, side by side)

cinder temple
#

The solution here is you put both in the same OnBubbleAdded, which is what we've been trying to do from the start.

slow merlin
#

The scripts are in two separate buttons in a GUI. Do I just put the contents of the bubble OnBubbleAdded code into the text OnBubbleAdded code? Or do I copy over the entire OnBubbleAdded code for the Bubble Color?

cinder temple
#

The first one, yes.

#

You already have the BackgroundColor value of the player inside your customPlayerChat table.. Access it from there

slow merlin
#

Oh wow, it actually worked! Thank you so much!

#

I'm gonna make separate reset buttons for all of these, so players can change back.

cinder temple
#

No problem, I just hope you understood what you did to get to this point

slow merlin
#

I do, it's mainly the overwriting stuff that I need to note down and not forget.

cinder temple
#

Yea that one's a bit tricky, it doesn't work how normal functions work

#

Congrats nonetheless 😄

slow merlin
#

@cinder temple Heya, I wanted to say thanks for your help again.
I really didn't want to bother you again with this, but unfortunately I've come up with a problem. I don't think this one's as big, but I have technically finished everything I've needed to do.

The problem is that the text bubble doesn't appear when a player sends a message, until they apply a colour.

E.g. If I speak without applying a colour, nothing happens. However, if I set my text-colour to pink, then it will change successfully, and the bubble will be the default colour, as intended.

I get this error here, do you know what the problem could be?
-# Once again, sorry if I bothered you!