System chat messages are local... again?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the system chat messages to appear on every player’s screen in the server.
  2. What is the issue? Include screenshots / videos if possible!
    The chat message only appears on one screen.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I made a remote event that fires from a server script to a local using RemoteEvent:FireAllClients(). The thing is, it still doesn’t seem to work. I made a post like this and people did give me useful advice, but I wasn’t familiar with the topic.

Script inside a part that fires remote when touched:

local dbtable = {}

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player and not dbtable[player.Name] then
			dbtable[player.Name] = true
			game.ReplicatedStorage.GetTimeAndStop:InvokeClient(player)
			game.ReplicatedStorage.GiveTowers.OnServerEvent:Connect(function()
				player.leaderstats.Towers.Value = player.leaderstats.Towers.Value + 1
				print("Received remote event message and gave player a tower point.")
			end)
			game.ReplicatedStorage.ChatMessageComplete:FireAllClients()
			wait(10)
			dbtable[player.Name] = false
		end
	end
end)

Ignore other code

Function inside of a local script in a textlabel in a screen gui in the starter gui that receives event:

local function stoptimerandgettime()
	local timertime = script.Parent.Text
	player.Character.Humanoid.Health = 0
	player.Character.HumanoidRootPart.Position = workspace.Lobby.WinnerSpawn.Position
	game.ReplicatedStorage.GiveTowers:FireServer()
	game.ReplicatedStorage.ChatMessageComplete.OnClientEvent:Connect(function()
		local brickcolor = BrickColor.new("Bright yellow")
		game.StarterGui:SetCore("ChatMakeSystemMessage",{
			Text = player.Name.." has beaten the tutorial tower in: "..timertime;
			Font = Enum.Font.Cartoon;
			Color = brickcolor.Color;
			FontSize = Enum.FontSize.Size96;
		})
	end)
end

Please help if you can!

I believe the issue you are facing is related to the positioning of the ChatMessageComplete.OnClientEvent:Connect() in the local script. Since it is inside the stoptimerandgettime() function, it is only checking for the remote event once the function has been called. Since the function is called only on the client who touched the part, it is only testing for the remote function on the player/client who touched the part and hence is not sending the system message to everyone - only the client who touched the part.

A simple fix for this would be to put the Connect() function outside of the function. If you would prefer a copy-paste method here you go (local script):

 local function stoptimerandgettime()
    player.Character.Humanoid.Health = 0
   	player.Character.HumanoidRootPart.Position = workspace.Lobby.WinnerSpawn.Position
   	game.ReplicatedStorage.GiveTowers:FireServer()
 end

 game.ReplicatedStorage.ChatMessageComplete.OnClientEvent:Connect(function()
   	local brickcolor = BrickColor.new("Bright yellow")
    local timertime = script.Parent.Text
   	game.StarterGui:SetCore("ChatMakeSystemMessage",{
   		Text = player.Name.." has beaten the tutorial tower in: "..timertime;
   		Font = Enum.Font.Cartoon;
   		Color = brickcolor.Color;
   		FontSize = Enum.FontSize.Size96;
   	})
  end)

This is only a speculation based on the code and information provided, so let me know if this works or not - i’ll be happy to help if it doesn’t.

1 Like

Hello @AstonAceMan! After trying your method, it seemed to work at first, but it was weird. When a player finished the obby, it said that player’s name has finished the obby in their time, but on the second player’s screen, it said their name has completed the obby with no time. I have no idea what is going on. Here is the function now, and I am pretty sure I did everything correctly, but did I do something wrong?

Code:

local function stoptimerandgettime()
	player.Character.Humanoid.Health = 0
	player.Character.HumanoidRootPart.Position = workspace.Lobby.WinnerSpawn.Position
	game.ReplicatedStorage.GiveTowers:FireServer()
end

game.ReplicatedStorage.ChatMessageComplete.OnClientEvent:Connect(function()
	local brickcolor = BrickColor.new("Bright yellow")
	local timertime = script.Parent.Text
	game.StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = player.Name.." has beaten the tutorial tower in: "..timertime;
		Font = Enum.Font.Cartoon;
		Color = brickcolor.Color;
		FontSize = Enum.FontSize.Size96;
	})
end)

Please help!

That’s probably because the paremeter called player was never assigned

In the beginning of the script though, there is a player variable. Would I still need the argument?

Sorry for the late response, I live in a tricky timezone so I had to get some sleep.

Hopefully this will work. The time variable from the player who completes it needs to be passed as an argument to all the other players. You also need to pass the player’s name as an argument for the other clients to use.

Here is your server-side script with some things changed to allow for an argument:

local dbtable = {}

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player and not dbtable[player.Name] then
			dbtable[player.Name] = true
			local timer = game.ReplicatedStorage.GetTimeAndStop:InvokeClient(player) --collect the return value into 'timer' variable
			game.ReplicatedStorage.GiveTowers.OnServerEvent:Connect(function()
				player.leaderstats.Towers.Value = player.leaderstats.Towers.Value + 1
				print("Received remote event message and gave player a tower point.")
			end)
			game.ReplicatedStorage.ChatMessageComplete:FireAllClients(timer, player.Name) --parse the time and player name to all clients
			wait(10)
			dbtable[player.Name] = false
		end
	end
end)

And here is the edited client-side localscript:

local function stoptimerandgettime()
	player.Character.Humanoid.Health = 0
	player.Character.HumanoidRootPart.Position = workspace.Lobby.WinnerSpawn.Position
	game.ReplicatedStorage.GiveTowers:FireServer()
    return script.Parent.Text --return the timer value to the server
end

game.ReplicatedStorage.ChatMessageComplete.OnClientEvent:Connect(function(timertime, playername)
    --collect the timer value from the server into variable 'timertime'
	local brickcolor = BrickColor.new("Bright yellow")
	game.StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = playername.." has beaten the tutorial tower in: "..timertime; --use 'timertime' as per normal
		Font = Enum.Font.Cartoon;
		Color = brickcolor.Color;
		FontSize = Enum.FontSize.Size96;
	})
end)

Edit: Added comments to code for easier understanding.
Edit 2: Added username as an argument because I forgot you needed this also.
Edit 3: I’m a bit silly and forgot you cant use time as a variable. Changed it to timer

1 Like