Ad
Log in to vote
1

Why doesn't ChatMakeSystemMessage work inside PlayerAdded Events?

Asked by
Soban06 410 Moderation Voter
2 years ago

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

0
Have you only tested it solo? Raccoonyz 1092 — 2y
0
When you tested this, did you get another player to check if the system message appears on their screen? gskw 1046 — 2y
0
@Raccoonyz Yes. I have only tested it in roblox studio as solo. Soban06 410 — 2y
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? Soban06 410 — 2y
0
I think ChatMakeSystemMessage is client-side, maybe try to fire a remoteEvent on all clients and create the message from the client... Xx_XSanderPlayXx 160 — 2y

2 answers

Log in to vote
-1
Answered by
TTChaos 750 Moderation Voter
2 years ago

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)
0
Thanks! Soban06 410 — 2y
0
k3du53 is sad TTChaos 750 — 2y
0
Also, if Soban06 rejoins the game, this won't make the message a second time. k3du53 152 — 2y
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. TTChaos 750 — 2y
Ad
Log in to vote
1
Answered by
k3du53 152
2 years ago

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

Answer this question