Hello! I’m making a RNG game and sends a global chat message if the player gets a 1 in 5M or more. I released my game, pulled it, and it didn’t go well… I got it, but it displays everyone in the server. I’m trying to find out what’s happening but I can’t. Below is my picture and all of my scripts, thank you for helping!
ChatRolling LocalScript(Inside StarterPlayer StarterPlayerScripts)
local c = game.ReplicatedStorage.ChatEvents.Chat
local FormatNumber = require(game.Workspace.FormatNumber.Main)
local formatter = FormatNumber.NumberFormatter.with()
local m = game:GetService("MessagingService")
c.GlobalMessages.OnClientEvent:Connect(function(Message)
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message.Data)
end)
c.DonationEvent.OnClientEvent:Connect(function(plr)
if plr then
local Message = `<font color="#00ff00">[DONATION] {plr} has donated 10 Robux!</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
end
end)
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">WOW! {plr.Name} has rolled an 1/{displayer}!</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
elseif index >= 1000000 and index < 5000000 then
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 >= 5000000 and index < 10000000 then -- 1/5M+
local displayer = formatter:Format(index)
local Message = `<font color="#FF0000">{plr.Name} has rolled an 1/{displayer}! 🎉</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global1:FireServer(displayer)
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)
game.ReplicatedStorage.ChatEvents.Chat.Global2:FireServer(displayer)
elseif index >= 100000000 and index < 1000000000 then
local displayer = formatter:Format(index)
-- Light Lime hex code: #98FB98
local Message = `<font color="#98FB98">OMG! {plr.Name} has rolled an 1/{displayer}!✨✨✨</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global3:FireServer(displayer)
elseif index >= 1000000000 then
local displayer = formatter:Format(index)
-- Green hex code: #00FF00
local Message = `<font color="#00FF00">OMG! {plr.Name} has rolled an 1/{displayer}! 🔥🔥🔥</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global4:FireServer(displayer)
end
end)
GlobalChat (Script) inside ServerScriptService:
local m = game:GetService("MessagingService")
local r = game.ReplicatedStorage.ChatEvents.Chat
m:SubscribeAsync("GlobalChat", function(Message)
game.ReplicatedStorage.ChatEvents.Chat.GlobalMessages:FireAllClients(Message)
game.Lighting.TimeOfDay = "00:17:00"
wait(0.1)
game.Lighting.TimeOfDay = "00:22:00"
wait(0.15)
game.Lighting.TimeOfDay = "00:00:00"
wait(9.5)
game.Lighting.TimeOfDay = "00:04:00"
wait(0.15)
game.Lighting.TimeOfDay = "00:09:00"
wait(0.1)
game.Lighting.TimeOfDay = "12:00:00"
end)
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)
``
2 Likes
Each player in the server gets sent the non-global message saying what odds somebody rolled. You then checked if they rolled lucky odds and if they did you send it to the server again. However, you are not passing the player’s name who rolled the extreme odds and are instead only using each player who received the first, non-global message, which is everyone in the server.
I would personally handle the lucky rolls on the server-side but if you wanted to keep it on the client-side, you would do so by passing in the plr
value into the :FireServer()
:
-- LocalScript
game.ReplicatedStorage.ChatEvents.Chat.Global4:FireServer(plr, displayer)
-- Script
r.Global3.OnServerEvent:Connect(function(plr, playerWhoRolled, displayer)
local Message = `<font color="#98FB98">[🌎GLOBAL] OMG! {playerWhoRolled.Name} has rolled an 1/{displayer}!✨✨✨</font>`
m:PublishAsync("GlobalChat", Message)
end)
However, this does lead to the problem of multiple clients requesting that the server send this global message, meaning that it will show up multiple times if you don’t stop it from being sent more than once.
I would just handle the global check directly on the server-side using BindableEvents or in the same script.
-- Script
...
local global = --[[path to bindable event]]
if index >= 5000000 and index < 10000000 then
global:Fire(playerWhoRolled, displayer)
end
...
-- GlobalChat Script
global.Event:Connect(function(playerWhoRolled, displayer)
local Message = `<font color="#FF0000">[🌎GLOBAL] {plr.Name} has rolled an 1/{displayer}! 🎉</font>`
m:PublishAsync("GlobalChat", Message)
end)
2 Likes
I tried to do it how you just said (turning events to bindable), but now it only shows it in the server.
ChatRolling(Cilent):
local c = game.ReplicatedStorage.ChatEvents.Chat
local FormatNumber = require(game.Workspace.FormatNumber.Main)
local formatter = FormatNumber.NumberFormatter.with()
local m = game:GetService("MessagingService")
c.GlobalMessages.OnClientEvent:Connect(function(Message)
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message.Data)
end)
c.DonationEvent.OnClientEvent:Connect(function(plr)
if plr then
local Message = `<font color="#00ff00">[DONATION] {plr} has donated 10 Robux!</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
end
end)
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">WOW! {plr.Name} has rolled an 1/{displayer}!</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
elseif index >= 1000000 and index < 5000000 then
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 >= 5000000 and index < 10000000 then -- GLOBAL MESSAGES START
local displayer = formatter:Format(index)
local Message = `<font color="#FF0000">{plr.Name} has rolled an 1/{displayer}! 🎉</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global1:Fire(plr, displayer)
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)
game.ReplicatedStorage.ChatEvents.Chat.Global2:Fire(plr, displayer)
elseif index >= 100000000 and index < 1000000000 then
local displayer = formatter:Format(index)
-- Light Lime hex code: #98FB98
local Message = `<font color="#98FB98">OMG! {plr.Name} has rolled an 1/{displayer}!✨✨✨</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global3:Fire(plr, displayer)
elseif index >= 1000000000 then
local displayer = formatter:Format(index)
-- Green hex code: #00FF00
local Message = `<font color="#00FF00">OMG! {plr.Name} has rolled an 1/{displayer}! 🔥🔥🔥</font>`
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(Message)
game.ReplicatedStorage.ChatEvents.Chat.Global4:Fire(plr, displayer)
end
end)
GlobalChat(In serverscriptserivce)
local m = game:GetService("MessagingService")
local r = game.ReplicatedStorage.ChatEvents.Chat
m:SubscribeAsync("GlobalChat", function(Message)
game.ReplicatedStorage.ChatEvents.Chat.GlobalMessages:FireAllClients(Message)
game.Lighting.TimeOfDay = "00:17:00"
wait(0.1)
game.Lighting.TimeOfDay = "00:22:00"
wait(0.15)
game.Lighting.TimeOfDay = "00:00:00"
wait(19.5)
game.Lighting.TimeOfDay = "00:04:00"
wait(0.15)
game.Lighting.TimeOfDay = "00:09:00"
wait(0.1)
game.Lighting.TimeOfDay = "12:00:00"
end)
r.Global1.Event:Connect(function(playerWhoRolled, displayer)
print(displayer)
local Message = `<font color="#FF0000">[🌎GLOBAL] {playerWhoRolled.Name} has rolled an 1/{displayer}! 🎉</font>`
m:PublishAsync("GlobalChat", Message)
end)
r.Global2.Event:Connect(function(playerWhoRolled, displayer)
local Message = `<font color="#9D00FF">[🌎GLOBAL] {playerWhoRolled.Name} has rolled an 1/{displayer}! ✨</font>`
m:PublishAsync("GlobalChat", Message)
end)
r.Global3.Event:Connect(function(playerWhoRolled, displayer)
local Message = `<font color="#98FB98">[🌎GLOBAL] OMG! {playerWhoRolled.Name} has rolled an 1/{displayer}!✨✨✨</font>`
m:PublishAsync("GlobalChat", Message)
end)
r.Global4.Event:Connect(function(playerWhoRolled, displayer)
local Message = `<font color="#00FF00">[🌎GLOBAL] OMG! {playerWhoRolled.Name} has rolled an 1/{displayer}! 🔥🔥🔥</font>`
m:PublishAsync("GlobalChat", Message)
end)
Ah, my apologies.
I believe you can then send the message from the GlobalScript to all players.
When I try to print the displayer on r.Global.1, nothing happens.
1 Like