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

Why doesn't ChatMakeSystemMessage work inside PlayerAdded Events?

My question is very simple. Whenever I (the admin) of the game join, I the want the server to write the message in the chatbox "The Admin Has Joined The Game".

1st Step

I tried to make a simple ChatMakeSystemMessage inside StarterPlayer --> StarterPlayerScripts --> LocalScript.

Inside the local script, I first tried to do the below code. All this below code does is that is writes on the chatbox "The Admin has joined the game" whenever the server starts. Which I don't want.

game.StarterGui:SetCore("ChatMakeSystemMessage", {
	Text = "The Admin Has Joined The Game";
	Font = Enum.Font.Cartoon;
	FontSize = Enum.FontSize.Size24
})

2nd Step

So now I tried to make a PlayerAdded Event inside the LocalScript, and simply checked if the player who joined, if their name was "Soban06" (which is me). And if that was the case, we would write "The Admin Has Joined The Game". Else, we wouldn't do anything.

So here is my code with the PlayerAdded Event:

game.Players.PlayerAdded:Connect(function(Player)
	if Player.Name == "Soban06" then
		game.StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = "The Admin Has Joined The Game";
			Font = Enum.Font.Cartoon;
			FontSize = Enum.FontSize.Size24
		})
	end
end)

But when I do the above, nothing happens when I join the game. I am perfectly sure that when I join the game, my name on the leader board is the same as the one I mentioned in the script.

But nothing happens.

Please assist me in this.

Thanks

5 comments

0

Have you only tested it solo?

0

When you tested this, did you get another player to check if the system message appears on their screen?

0

@Raccoonyz Yes. I have only tested it in roblox studio as solo.

0

@gskw I tried it using the test feature in roblox studio. I started a test server in roblox studio with 2 players. But both of them can't see the admin joined message because their names are "Player1" and "Player2". Is there any way to include myself inside the test server? So that I can see if the message appears?

0

I think ChatMakeSystemMessage is client-side, maybe try to fire a remoteEvent on all clients and create the message from the client...

2 answers

✓ Accepted answer

Like k3du53 said, it won't actually fire for yourself. My solution constantly loops through over and over again to see if players got missed.

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local SentMessage = false

local function AdminMessage(Player)
	if Player.UserId == 617445798 and not SentMessage then
		StarterGui:SetCore("ChatMakeSystemMessage", {Text="{System} Admin has joined the game"})
		SentMessage = true
	end
end

local function LoopThroughPlayers()
	while true do
		for Index, Player in pairs(Players:GetChildren()) do
			if Player.UserId == 617445798 and not SentMessage then
				StarterGui:SetCore("ChatMakeSystemMessage", {Text="{System} An admin has joined the game"})
				SentMessage = true
			end
		end
		wait()
	end
end

Players.PlayerAdded:Connect(AdminMessage)

spawn(LoopThroughPlayers)

5 comments

0

Thanks!

0

k3du53 is sad

0

Also, if Soban06 rejoins the game, this won't make the message a second time.

0

@k3du53 The second one i found after answering this question, and i didn't know how to use it at the time. The first one, you misunderstood.

The game.Players.PlayerAdded event won't fire for yourself in a LocalScript, because you join the game before that script runs.

A potential solution would be to loop through the players and display the message if they exist.

ex.

game.Players.PlayerAdded:Connect(function(Player)
    if Player.Name == "Soban06" then
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = "The Admin Has Joined The Game";
            Font = Enum.Font.Cartoon;
            FontSize = Enum.FontSize.Size24
        })
    end
end)

for i,player in pairs(game.Players:GetPlayers()) do
	if player.Name == "Soban06"
		-- "The admin is in this game!" or something
	end
end

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