I’m trying to make a gui which changes the the players chat color when they press a certain textbutton or imagebutton, and make it viewable for all players!
Hey Skiloopski!
I’m assuming by chat color you’re referring to the bubble chat. If you are I can help!
So what’s important to know here is that the bubble chat is really just a BillboardGui and just like any BillboardGui, it can be manipulated.
Luckily, the client has Network Ownership of those ChatBubbles, so we can do all of this in a local script and other players will still see it!
First what you’ll want to do is locate the chat bubble, which can be found in:
game.Players.LocalPlayer.PlayerGui.BubbleChat
Now that we know where the BillboardGui will spawn, we can look inside it to find out exactly what’s going on here. Now inside of the BillboardGui looks like this:
So, what we’re looking for is the ImageLabel named ChatBubble, and the one inside that named ChatBubbleTail. To change the color of the background, we’ll need to change the color of both of those.
We can do that like this:
local BubbleChat = game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("BubbleChat")
local Color = Color3.new(1, 0, 0) -- red
BubbleChat.ChildAdded:Connect(function(Child) -- Waits for the BubbleChat ScreenGui to get a child, it will alwasy be a chat frame.
local BillboardFrame = Child:WaitForChild("BillboardFrame")
local FirstChat = BillboardFrame:FindFirstChild("ChatBubble")
FirstChat.ImageColor3 = Color
FirstChat:WaitForChild("ChatBubbleTail").ImageColor3 = Color -- We need to set this first because it won't register as a child added later since it was added before now.
BillboardFrame.ChildAdded:Connect(function(ChatBubble) -- Picking up every chat bubble added into the frame
if not ChatBubble.Name == "ChatBubble" then return end
ChatBubble.ImageColor3 = Color
ChatBubble:WaitForChild("ChatBubbleTail").ImageColor3 = Color
end)
end)
Oh sorry for not mentioning, I meant, the chat bar.
You can put the player onto a team of the colour you want, and their player name in the chat will be the colour of the team they are in.
@RepValor very nicely written answer, I learned something new from that
Thanks! So much! I feel really dumb, hehe.
Please remember to do some research and make attempts before posting threads on the DevForum.
If you wish to change a player’s chat colour after pressing a button (and not just their name colour), first you need to find out what button you’re working with and establish a button click connection. From there, have it fire a remote to the server requesting a colour change.
From the server’s end, it can receive the client’s request through the aforementioned remote and set to work on changing the player’s chat colour. Although not providing you a full code sample, here is the basic idea of what you could be looking to work with:
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local speaker = ChatService:GetSpeaker(player.Name)
if speaker then
speaker:SetExtraData("ChatColor", Color3.new(1, 0, 0))
end