Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make system message server-sided?

I have code that will send a system message in the chat about which player joined or left. It uses a RemoteEvent in ReplicatedStorage to send the message.

The problem is that when I join the game and I go on my alt and join the same server, the message about the player who joined was only on that player's side, or client-sided.

How can I make it server-sided?

Codes:

LocalScript:

local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("PlayerJoinedorRemoved") 

Remote.OnClientEvent:Connect(function(action)
	if action == "Joined" then
		game.StarterGui:SetCore("ChatMakeSystemMessage", {  
			Text = (Player.Name.." has joined the server.");
			Color = Color3.fromRGB(121, 255, 188);
			Font = Enum.Font.ArialBold;
		})

	elseif action == "Left" then
		game.StarterGui:SetCore("ChatMakeSystemMessage", {  
			Text = (Player.Name.." has left the server.");
			Color = Color3.fromRGB(255, 51, 71);
			Font = Enum.Font.ArialBold;
		})
	end
end)

Server Script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("PlayerJoinedorRemoved")

Players.PlayerAdded:Connect(function(playerAdded)
	RemoteEvent:FireClient(playerAdded,"Joined") 
end)

Players.PlayerRemoving:Connect(function(playerRemoved)
	RemoteEvent:FireClient(playerRemoved,"Left")
end)

1 answer

The issue is that you're firing the remote event to that specific player that joined, and not everyone else. You should use :FireAllClients to fire the remote event to all the players.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("PlayerJoinedorRemoved")

Players.PlayerAdded:Connect(function(playerAdded)
    RemoteEvent:FireAllClients(playerAdded,"Joined") 
end)

Players.PlayerRemoving:Connect(function(playerRemoved)
    RemoteEvent:FireAllClients(playerRemoved,"Left")
end)

1 comment

0

I joined the game and nothing appearing in the chat. Is that normal?

This discussion is preserved as it was. New answers, comments, and votes are closed.