Global Message not being Possible to send after Using Command

Hello, there! How are you?

In Roblox Studio, I decided to create a Global Message system that allows specific players to submit a message using a custom command, /announce! Eventually, once making the code while following the tutorial, everything seemed normal… Until a message on the Output tab appeared stating the argument is got something else that should not be expected

local MessageService = game:GetService("MessagingService")
local ReplictedStore = game:GetService("ReplicatedStorage")
local Players = game.Players

local Notification = ReplictedStore.GlobalAnnouncementSystem:WaitForChild("Notify")

local Command = "/announce"

Players.PlayerAdded:Connect(function(player)
	if (player).Name == "JuanGamerPlayz_RBLX" and "Viewported" then
		player.Chatted:Connect(function(message)
			local SplitMessage = message:split(" ")
			if (SplitMessage)[1] == Command then
				MessageService:PublishAsync("Global Announcement", message:sub(tostring(SplitMessage[1]), " "))
				Notification:FireAllClients(player, "Success", "Your Message has been fully sent.")
			end
		end)
	end
	
	
	
end)

MessageService:SubscribeAsync("Global Announcement", function(Message)
	Notification:FireAllClients("Global Announcement", Message["Data"])
end)

image

Can someone help me out with this? I appreciate the support!

Thank you

You mean to put gsub? Cause sub works like this:

local hi = "I love roblox!"
print(hi:sub(8, 13)) -- Will print "roblox"

and gsub works like this:

local hi = "I love roblox!"
print((hi:gsub(" ", ""))) -- Will print "Iloveroblox!"

bbbbbbbbbbbb

I think what you’re wanting is table.concat(),

table.concat(SplitMessage, " ", 1) -- the number is the index at which it begins

Now it is giving a warning line in the Notification:FireAllClients(player, "Success", "Your Message has been fully sent.")… Not sure why the script is not working as expected from this tutorial:

I can try:

local MessageService = game:GetService("MessagingService")

local ReplictedStore = game:GetService("ReplicatedStorage")
local Players = game.Players

local Notification = ReplictedStore.GlobalAnnouncementSystem:WaitForChild("Notify")

local Command = "/announce"

Players.PlayerAdded:Connect(function(player)
	if (player).Name == "JuanGamerPlayz_RBLX" and "Viewported" then
		player.Chatted:Connect(function(message)
			local SplitMessage = message:split(" ")
			if (SplitMessage)[1] == Command then
				MessageService:PublishAsync("Global Announcement", message:gsub(tostring(SplitMessage[1]), " "))
				Notification:FireAllClients(player, "Success", "Your Message has been fully sent.")
			end
		end)
	end
	
	
	
end)

MessageService:SubscribeAsync("Global Announcement", function(Message)
	Notification:FireAllClients("Global Announcement", Message["Data"])
end)

It worked as not printing errors, yet it needed to show a message globally for everyone

Update the topic, this should explain further to everyone

Probably cause of this? Your checking if the player’s name is 2 different names.

If I create a variable which waits for both players to appear in the game, maybe this can help?

What do you mean?

gggggggggggggggggggggg

Basically, if I create a variable called Juan and View where it waits for us to join the game, it can be possible to put the variables in the if statement and continue further with the progress! (Actually, while messaging you, I just thought straight ahead that it would be better if get the names through a table/by UserId, but uncertain how it could be structured afterwards in the code lines.)

“FireAllClients” with the first parameter being the player? change it for FireClient

1 Like

Okay, so I have returned to the script replacing the event with FireClient and once testing the command such as saying “/announce Hi”, it seems that in the Output, it prints an error stating that FireClient is not a valid member somehow