Global Chatting Game System - The Next Way To Chat With A Lot Of Players

Hello! TechGroupMedia here!

If you want to just learn how to build it, you can scroll down until you see How To Make.

A few months ago, I released a project onto the Devfourm known as Chat Assistant, View it Here: Chat Assistant- The Next Way To Communicate With Others
Anyway, I think people enjoyed it as 60 people voted and 43 said that they liked it.
Now, I Remade the project into a better one, that fixed an issue. Messaging Service has its flaws, such as a limit to the number of messages that can be sent. This product has a Filter still in Beta that detects if the limit has been reached using algorithms and, will wait a minute until posting the message.
With this note, there might still be some bugs, you can message me @TechGroupMedia. Anyways, let’s get started on the Project! :smiley:

How To Make:

  1. Load up Roblox Studio.
    You need Roblox Studio for this.

  2. Load up the game
    Load up the game you want the Global Chatting Game System to be on.

  3. Put a script into ServerScriptService
    Place a script into ServerScriptService and name it “GlobalChattingSystemMain”

4.Place a Local Script into Starter Player < StarterPlayerScripts
Place a Local Script into Starter Player < StarterPlayerScripts and name it “GlobalChattingSystemClient”

  1. Place a RemoteEvent into ReplicatedStorage
    Place a RemoveEvent into ReplicatedStorage and call it “NewChatFromServer”

  2. Make sure your game looks like this:
    image

  3. Now please go to GlobalChattingSystemMain and put in the Following Code:

local MessagesLeftToSend = 0
local ValueBefore = 0
game.Players.PlayerAdded:Connect(function(plr)
	
	
	local playersinServer = 0
	print(plr.Name.." Has Joined!")
	repeat wait() until plr
	for i,v in pairs(game.Players:GetPlayers()) do
		playersinServer = playersinServer +1
	end
	wait(0.1)
	local Value1 = playersinServer*60
	local Value2 = Value1+150
	if MessagesLeftToSend == Value2  then
		ValueBefore = Value2
	else
		local Minus = ValueBefore - MessagesLeftToSend
		local Value = Value2 - Minus
		ValueBefore = Value
		MessagesLeftToSend = Value
	end
	print("function ended 1")
end)
game.Players.PlayerRemoving:Connect(function()
	local playersinServer = 0
	for i,v in pairs(game.Players:GetPlayers()) do
		playersinServer = playersinServer +1
	end
	wait(0.1)
	local Value3 = playersinServer-1
	local Value1 = Value3*60
	local Value2 = Value1+150
	if MessagesLeftToSend == Value2  then
		ValueBefore = Value2
	else
		local Minus = ValueBefore - MessagesLeftToSend
		local Value = Value2 - Minus
		ValueBefore = Value
		MessagesLeftToSend = Value
	end
end)
local function IsPlayerInGame(player)
	local Var  = false  
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Name == player then
			Var = true-- change to true
		end
	end
	wait()
	if Var == true then
		return true
	elseif Var == false then
		return false
	end
end
local function MessageSent()
	local Value = MessagesLeftToSend - 1
	MessagesLeftToSend = Value
	wait(60)
	MessagesLeftToSend = MessagesLeftToSend +1
end
game.Players.PlayerAdded:Connect(function(plr)plr.Chatted:Connect(function(msg)
		if MessagesLeftToSend <= 0 then
			print("Maximum Messages Sent, Messages will be sent to Servers in 1 minute.")
			wait(60)
		local Filter = game.Chat:FilterStringForBroadcast(msg,plr)
		local Data = {plr.Name,Filter}
		local Code = game.HttpService:JSONEncode(Data)
		local MS = game:GetService("MessagingService")
		MS:PublishAsync("Chat",Code)
			MessageSent()
		else
			local Filter = game.Chat:FilterStringForBroadcast(msg,plr)
			local Data = {plr.Name,Filter}
			local Code = game.HttpService:JSONEncode(Data)
			local MS = game:GetService("MessagingService")
			MS:PublishAsync("Chat",Code)
			MessageSent()
			end
	end)end)

game:GetService("MessagingService"):SubscribeAsync("Chat",function(Data)
	local Info = Data.Data
	local NewInfo = game.HttpService:JSONDecode(Info)
	local PlrthatSentMessage = NewInfo[1]
	local MessageInfo = NewInfo[2]
	if IsPlayerInGame(PlrthatSentMessage) == false then
		game.ReplicatedStorage.NewChatFromServer:FireAllClients(PlrthatSentMessage,MessageInfo)
	end
end)
  1. Now, go over to the LocalScript, GlobalChattingSystemClient, and put this code in:
game.ReplicatedStorage.NewChatFromServer.OnClientEvent:Connect(function(plrthatSent,Msg)
	game.StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = "["..plrthatSent.."]: "..Msg;
		Font = Enum.Font.SourceSansBold;


	})
end)

You’re about done!

  1. Click Game Settings
    Click the Game Settings button on the top of your screen.

  2. Click Security and Enable HTTP Service and Studio Access to API Services.
    A little bit of the script uses HTTP Service to Encode a Table.

  3. Publish the game and you should be done!

Remember, this is still in Beta. Please message me if there are any errors. Please don’t claim it as your own, it isn’t, Babycorndog10 and I made it.
Cool Features:
Uses Messaging Service
Filters the messages using Roblox’s Chat Filter
Manages the messages sent limit
Can Control many things.

Want to customize it a bit? Click the Extra Features button below to see what you can add!

Extra Features
How to change the Chat Color or Font

Go to Starter Player < StarterPlayerScripts and open GlobalChattingSystemClient.
To change the Font:
Find where it says font, you Can delete SourceSansBold and Pick from the options.

To change the Color:
Right Below Font, Write Color
image
Now make it say Color = BrickColor.new()
Between the parentheses, put a string and choose a Color.
When your done selecting the color, put .Color; behind it.
image

How to change the Chat Tag

Go to Starter Player < StarterPlayerScripts and open GlobalChattingSystemClient.
Find Text, most likely going to be on Line 3.
After the equal sign, there should be a String. This is what the Text is going to be.
You can make it in

If you just want to insert it, you can run this Code: Works both in Command Bar and in a Script.

game:GetService("InsertService"):LoadAsset(6104167920).Parent = game.Workspace

If you want to test the script, you can visit this game:
https://www.roblox.com/games/6100737077/New-Chat-Server-Testing

How helpful was the Tutorial? 10 being the best
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

0 voters

8 Likes

There’s a number of bad practices in your implementation and you are completely overcomplicating it. Just with the amount of code here that could use improvement I decided to only provide a few examples, otherwise I would be rewriting this for you.

I suppose the people using this tutorial aren’t the same people who have a good understanding of Lua, at least not enough to make something like this. Nonetheless, here’s some of the big things I see:

plr refers to the Player returned by PlayerAdded. There’s no need to be trying to wait for it like this, it will exist right away.

repeat wait() until plr

You loop through all of the players to get the total amount, this isn’t needed. You can simply do # game.Players:GetChildren() (I added a space after the # so it isn’t formatted oddly in this post)

	for i,v in pairs(game.Players:GetPlayers()) do
		playersinServer = playersinServer +1
	end
6 Likes

Do you have examples of production usage? Could you add a demonstration game (that’s uncopylocked)? Would it be possible to make an insertion ModuleScript which you can require in the command bar to install this? (If you need help with that, let me know :upside_down_face:)

I am just making sure with the repeat. I know the player is added, but in some cases, they aren’t already.
The GetPlayers is the same as getting Children so, but it’s making sure the model is a player.

I will try to get to work on that! :slight_smile:

I know the player is added, but in some cases, they aren’t already.

This is inaccurate. The player object exists right away. The character, on the other hand, does not.

The GetPlayers is the same as getting Children so, but it’s making sure the model is a player.

This doesn’t really change the fact that you can do # game.Players:GetPlayers() instead. No reason for any sort of iteration through the players to add the count manually.

2 Likes

Its just to make sure. If you dont like it, I am completely fine with that. Like I said, this is still in BETA and I will release multiple versions, and in the end I will have a finished product.

Ok! I got it done! You can run this code for it to work!

game:GetService("InsertService"):LoadAsset(6104167920).Parent = game.Workspace

When it loads, it automatically detects the players, gives them the scripts, and when a player joins, also gives them the script.

So, it will work both from a script and a Command bar.

Its just to make sure.

That’s a really bad argument. With this logic, I could apply it to anything. There isn’t a case where the player object wouldn’t exist right away, it never happens. Why don’t you add the repeat wait() everywhere in your code if you’re going to use it uselessly?

Regardless, given just how messy and inefficient your code is, and since I had 10 minutes to spare, I decided to rewrite it entirely.

Here’s the server:

-- GlobalChat.lua
-- ForcyDorcy
-- December 18th, 2020


local Chat = game:GetService("Chat")
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local MessagingService = game:GetService("MessagingService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


function PublishAsync(Data)
	local Success, Result = pcall(function()
		MessagingService:PublishAsync("Chat", Data)
	end)
end


function OnPlayerAdded(Player)
	Player.Chatted:Connect(function(Message)
		local FilteredText = Chat:FilterStringForBroadcast(Message, Player)
		local Data = {Player.Name, FilteredText}
		local EncodedData = HttpService:JSONEncode(Data)
		PublishAsync(EncodedData)
	end)
end


function OnMessageAsync(Data)
	ReplicatedStorage.GlobalChat:FireAllClients(Data[1], Data[2])
end


Players.PlayerAdded:Connect(OnPlayerAdded)
for _, Player in pairs(Players:GetPlayers()) do
	spawn(function()
		OnPlayerAdded(Player)
	end)
end


MessagingService:SubscribeAsync("Chat", function(Message)
	OnMessageAsync(Message.Data)
end)

Here’s the client:

-- ClientGlobalChat.lua
-- ForcyDorcy
-- December 18th, 2020


local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")



local GlobalChat = ReplicatedStorage:WaitForChild("GlobalChat")


function OnGlobalChat(Name, Message)
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "[" .. Name .. "]: " .. Message,
		Font = Enum.Font.SourceSansBold
	})
end


GlobalChat.OnClientEvent:Connect(OnGlobalChat)

If you really want to take it further, you can implement a repeat system on dropped publish requests on the server, and you can impliment a queue. Otherwise, the code here is light years ahead of your original posting. Feel free to use it however you’d like, FOSS.

5 Likes

I like it a bit. But what happens if someone in the server sends too many messages?

And as I said, it is still in beta and I am constantly fixing it.

PublishAsync is run in a protected call. The error would be encapsulated. Like I said, you can add a repeat system for retrying or you can add a queue system of sorts. That literally took me under 10 minutes to write compared to your beta code, if you’re really looking for PRODUCTION code, you can add that.

1 Like

In the future, I will make it a professional product with Major and small bugs fixed.

There shouldn’t be any bugs in my code, if you see any let me know. Here’s an example of a repeat system because if you want to implement this it shouldn’t really take longer than 5-10 minutes.

local Attempts = 0
local Success
repeat
	Attempts += 1
	Success = pcall(function()
		MessagingService:PublishAsync("Chat", Data)
	end)
	if (not Success) then
		wait(0.75 + (0.5 * math.random()))
	end
until (Success) or (Attempts == 3)

if (not Success) then
	-- It didn't send after three attempts, maybe add it to a queue and try again later.
end

Again, I just wrote that in like five minutes. This isn’t anything special, something like this shouldn’t take very long.

1 Like

Doing repeat isn’t very efficient, I only used it because I’m very sure the player is there, but it just makes sure. I really appreciate your help, but I think I don’t need it anymore. I will work on the Final Global Chatting Game system with a brand new name and fix a lot of things. Thanks though! :slight_smile:

Out of curiosity, what makes my system of repeat inefficient? Just asking because my method has been used in official Roblox templates such as the Galactic Speedway and Move It Simulator games (go check).

I just found it really ironic you are telling me using repeat is inefficient when you are running a repeat loop with wait() until the Player object from .PlayerAdded exists, which is something that exists right away.

6 Likes