Global Chat Message Display

I am making a RNG game, but I want to display the message “Player has rolled an 1/x!” if the player rolls an 1 in 1,000,000 or above. I have tried to look through the Devforum but it doesn’t really help my problem, and then I tried to watch YT tutorials but they were confusing. My script is below(starterplayerscripts localscript) and help is appreciated! Keep in mind the chat works but not globally.

local c = game.ReplicatedStorage.ChatEvents.Chat
local FormatNumber = require(game.Workspace.FormatNumber.Main)
local formatter = FormatNumber.NumberFormatter.with()

c.Over1K.OnClientEvent:Connect(function(plr, index)
	if index >= 1000 and index < 10000 then
		local displayer = formatter:Format(index)
		-- Gold hex code: #ffaa00
		local Message = `<font color="#ffaa00">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 10000 and index < 100000 then
		local displayer = formatter:Format(index)
		-- Cyan hex code: #04AFEC
		local Message = `<font color="#04AFEC">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 100000 and index < 1000000 then
		local displayer = formatter:Format(index)
		-- Pink hex code: ##FF00BF
		local Message = `<font color="##FF00BF">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 1000000 and index < 10000000 then -- 1/1M to 1/9.99M, where I want to send message to global chat!
		local displayer = formatter:Format(index)
		-- Red hex code: #FF0000
		local Message = `<font color="#FF0000">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 10000000 and index < 100000000 then
		local displayer = formatter:Format(index)
		-- Purple hex code: #9D00FF
		local Message = `<font color="#9D00FF">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 100000000 and index < 1000000000 then
		local displayer = formatter:Format(index)
		-- Light Lime hex code: #98FB98
		local Message = `<font color="#98FB98">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	elseif index >= 1000000000 then
		local displayer = formatter:Format(index)
		-- Green hex code: #00FF00
		local Message = `<font color="#00FF00">{plr.Name} has rolled an 1/{displayer}!</font>`
		game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
	end
end)

To make it work globally, you need to fire the remote event to every client. To do this, instead of doing game.ReplicatedStorage.ChatEvents.Chat:FireClient(...), do game.ReplicatedStorage.ChatEvents.Chat:FireAllClients(...). Note that when using :FireAllClients(), you do not pass a player object as the first argument.

Your actual script could do with some formatting changes to make it easier to read, but it doesn’t need any actual changes to make this global message work - just make sure to fire to all clients instead of just one player.

1 Like

I was firing all cilents, not one player.

What do you mean by it works but not globally? Does global mean every player in the current server or every player in every server

It only displays in the server, but I want to display in ALL SERVERS.

Then messaging service is your best friend. You should research it because it allows you to send messages to all servers. Resources:

I might start now. This is the time I need it.

it didnt show? (no errors and in a different script)

local m = game:GetService("MessagingService")
local r = game.ReplicatedStorage.ChatEvents.Chat

r.Global1.OnServerEvent:Connect(function(plr, displayer)
	local Message = `<font color="#FF0000">[GLOBAL]: {plr.Name} has rolled an 1/{displayer}! 🎉</font>`
	m:PublishAsync("GlobalChat", Message)
end)

r.Global2.OnServerEvent:Connect(function(plr, displayer)
	local Message = `<font color="#9D00FF">[GLOBAL]: {plr.Name} has rolled an 1/{displayer}! ✨</font>`
	m:PublishAsync("GlobalChat", Message)
end)

r.Global3.OnServerEvent:Connect(function(plr, displayer)
	local Message = `<font color="#98FB98">[GLOBAL]: OMG! {plr.Name} has rolled an 1/{displayer}!✨✨✨</font>`
	m:PublishAsync("GlobalChat", Message)
end)

r.Global4.OnServerEvent:Connect(function(plr, displayer)
	local Message = `<font color="#00FF00">[GLOBAL]: OMG! {plr.Name} has rolled an 1/{displayer}! 🔥🔥🔥</font>`
	m:PublishAsync("GlobalChat", Message)
end)

wheres ur script that does the SubscribeAsync (an event that watch for all servers)

didnt have the script. where do i do it

in serverscript, its something like

local MessageService = game:GetService("MessagingService")

MessageService:SubscribeAsync("Key", function(received)
	local ReceivedData = received.Data
	local timereceived = received.Sent
	
	print(ReceivedData)
end)
m:SubscribeAsync("GlobalMessages", function(Message)
	print(Message)
end)

didnt show that message

because ur PublishAsync key is (“GlobalChat”) not (“GlobalMessages”)

it got printed but how do i display it? i heard you could do in the localscript
edit: i was right

local MessageService = game:GetService("MessagingService")

MessageService:SubscribeAsync("Key", function(received)
	local ReceivedData = received.Data
	local timereceived = received.Sent
	
	print(ReceivedData) -- The actual thing u sent
	RemoteEvent:FireAllClients(ReceivedData) -- send the message to all players
end)

and this in client

RemoteEvent.OnClientEvent:Connect(function(Message)
	game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
end)

it works out fine! thank you!!

1 Like

idk why its printing “1 in electricpeapvz” but i’ll fix

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