Force chat system help?

How would i go about making a force chat system?

1 Like

Please explain what you mean with this.

Force the chat window as being opened?

1 Like

If you wanna make someone have a chat bubble of whatever you want on their head
(since from what I know roblox isnt the biggest fan of genuine force chats)

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

local chr = Players.lalalathisisafakename.Character

TextChatService:DisplayBubble(chr, "this my message")


(untested, but should work)

1 Like

Alright, you need to break this down into two parts:

Part 1: Chat Bubble

The chat bubble part is decently simple you could just add a chat bubble above the person’s head like this:

local TextChatService = game:GetService("TextChatService")

game.ReplicatedStorage.Chat.OnClientEvent:Connect(function(MSG,Part)
  TextChatService:DisplayBubble(Part,MSG)
end)

Part Two: Sending the message in chat

This is harder because you have to use algorithms to find the player chat color I found this

You could do this like this:

local NAME_COLORS =
{
	Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
	Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
	Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
	BrickColor.new("Bright violet").Color,
	BrickColor.new("Bright orange").Color,
	BrickColor.new("Bright yellow").Color,
	BrickColor.new("Light reddish violet").Color,
	BrickColor.new("Brick yellow").Color,
}

local function GetNameValue(pName)
	local value = 0
	for index = 1, #pName do
		local cValue = string.byte(string.sub(pName, index, index))
		local reverseIndex = #pName - index + 1
		if #pName%2 == 1 then
			reverseIndex = reverseIndex - 1
		end
		if reverseIndex%4 >= 2 then
			cValue = -cValue
	end
		value = value + cValue
	end
	return value
end

local color_offset = 0
local function ComputeNameColor(pName)
	return NAME_COLORS[((GetNameValue(pName) + color_offset) % #NAME_COLORS) + 1]
end

local TextChatService = game:GetService("TextChatService")

game.ReplicatedStorage.Chat.OnClientEvent:Connect(function(MSG,Username)
  Local ChatColor = ComputeNameColor(Username)

  TextChatService:WaitForChild("TextChannels").RBXGeneral:DisplaySystemMessage(<font color='"..ChatColor.."'>"..Username..": </font>".. MSG))
end)

All of this combined:

local NAME_COLORS =
{
	Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
	Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
	Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
	BrickColor.new("Bright violet").Color,
	BrickColor.new("Bright orange").Color,
	BrickColor.new("Bright yellow").Color,
	BrickColor.new("Light reddish violet").Color,
	BrickColor.new("Brick yellow").Color,
}

local function GetNameValue(pName)
	local value = 0
	for index = 1, #pName do
		local cValue = string.byte(string.sub(pName, index, index))
		local reverseIndex = #pName - index + 1
		if #pName%2 == 1 then
			reverseIndex = reverseIndex - 1
		end
		if reverseIndex%4 >= 2 then
			cValue = -cValue
	end
		value = value + cValue
	end
	return value
end

local color_offset = 0
local function ComputeNameColor(pName)
	return NAME_COLORS[((GetNameValue(pName) + color_offset) % #NAME_COLORS) + 1]
end

local TextChatService = game:GetService("TextChatService")

game.ReplicatedStorage.Chat.OnClientEvent:Connect(function(MSG,Username,Part)
  Local ChatColor = ComputeNameColor(Username)

  TextChatService:WaitForChild("TextChannels").RBXGeneral:DisplaySystemMessage(<font color='"..ChatColor.."'>"..Username..": </font>".. MSG))
  TextChatService:DisplayBubble(Part,MSG)
end)

Untested if you get any errors js tell me

BTW everything here is client sided.

One small thing ruins the entire system:

local NAME_COLORS =
	{
		Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
		Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
		Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
		BrickColor.new("Bright violet").Color,
		BrickColor.new("Bright orange").Color,
		BrickColor.new("Bright yellow").Color,
		BrickColor.new("Light reddish violet").Color,
		BrickColor.new("Brick yellow").Color,
	}

local function GetNameValue(pName)
	local value = 0
	for index = 1, #pName do
		local cValue = string.byte(string.sub(pName, index, index))
		local reverseIndex = #pName - index + 1
		if #pName%2 == 1 then
			reverseIndex = reverseIndex - 1
		end
		if reverseIndex%4 >= 2 then
			cValue = -cValue
		end
		value = value + cValue
	end
	return value
end

local color_offset = 0
local function ComputeNameColor(pName)
	return NAME_COLORS[((GetNameValue(pName) + color_offset) % #NAME_COLORS) + 1]
end

local TextChatService = game:GetService("TextChatService")

game.ReplicatedStorage.Chat.OnClientEvent:Connect(function(MSG,Username,Part)
	Local ChatColor = ComputeNameColor(Username) -- here

	TextChatService:WaitForChild("TextChannels").RBXGeneral:DisplaySystemMessage(<font color='"..ChatColor.."'>"..Username..": </font>".. MSG))
	TextChatService:DisplayBubble(Part,MSG)
end)

Maybe check your captalisation
Also, there seems to be something wrong where you set the colour of the text

1 Like

ForceChat.rbxl (54.6 KB)
Above is a working example with everything fixed, you can check it out

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.