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.
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)
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)