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

ChatMakeSystemMessage isn't working through player.Added, help?

Trying to make it so that it'll create a system message prompt in the chat when someone joins the game, but it isn't working. I'm doing this through a local script.

game:GetService("Players").PlayerAdded:Connect(function(Player)  --Event for when a player joins
	game.StarterGui:SetCore("ChatMakeSystemMessage", { --SetCore thingy
 		Text = Player.Name.." joined the game."; --Changes text
 		Font = Enum.Font.SourceSansSemibold; --Changes font
		Color = Color3.fromRGB(255,255,255); --Changes color
		FontSize = Enum.FontSize.Size96; --Changes fontsize
	})
end)

2 answers

✓ Accepted answer

Not a lot of context has been given but I'm assuming you ask why it isn't working for you.

Players.PlayerAdded is fired when a player joins a game. But listening for it from a local script, it will not fire for the local player.

Why?

The player already exists before the local scripts are cloned into the PlayerScripts/Backpack/etc folders.

How do we fix this?

Listen for this event server side and use a remote event to show the message.

On the client side you will be showing the system message and the server will fire that remote event to all the clients.

If you place this code into a ServerScript and read the output, you should notice that the game will warn that StarterGui:SetCore can only be called from a LocalScript

With this in mind, you will require a RemoteEvent to ask the Client to make this message in their chat. Since we presumably want all players to see the message, we need to use the :FireAllClients() method of RemoteEvents

REVISED SERVER SCRIPT under ServerScriptService

local remote = Instance.new("RemoteEvent")
remote.Name = "JoinServer"
remote.Parent = game:GetService("ReplicatedStorage")

game:GetService("Players").PlayerAdded:Connect(function(Player)
	remote:FireAllClients(Player.Name)
end)

REVISED LOCAL SCRIPT under StarterGui

local remote = game:GetService("ReplicatedStorage"):WaitForChild("JoinServer")

remote.OnClientEvent:Connect(function(name)
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {Text = name.." joined the game."; Font = Enum.Font.SourceSansSemibold; Color = Color3.fromRGB(255,255,255); FontSize = Enum.FontSize.Size96})
end)

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