Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to send messages to the chat with a script?

Asked by
Valatos 166
8 years ago

So I know some games, make stuff say in the chat when you join, I'm pretty sure they don't use a custom chat. How did they do that? Or is it just a custom chat? I searched on the wiki, on YouTube, even looked for a question asked about it, but I couldn't find anything.

2 answers

Log in to vote
1
Answered by 8 years ago

In terms of your original question, you want to use the SetCore function in StarterGui (see here) for an example of this. You will need to run the script in a LocalScript for it to work, and the message will only display on the player's screen for which the script is running.

Making a custom chat script is quite a different topic and it's not something I can explain into an answer to this question, but I suggest you check out this wiki article for more information. Sorry I can't explain this in an answer, but it is a very complicated topic and it is very technical.

1
Thanks! Didn't know I would needed to use the CoreGui. Valatos 166 — 8y
Ad
Log in to vote
2
Answered by
nanaluk01 247 Moderation Voter
8 years ago

If you want the server to "Chat" when the player joins and the player leaves, you would need to put this into a LocalScript inside StarterPlayerScript:

See comments in the code to get a better insight of how this script works!

If there are any typos, then please excuse me, I wrote this code here and now.

pcall(function() --Event that should fire when the player joins
    game.StarterGui:SetCore("ChatMakeSystemMessage", {
        Text = "[Server]: " ..game.Players.LocalPlayer.Name.. " has joined the game!";
        Color = Color3.new(255, 255, 255); --The color of the text
        Font = Enum.Font.SourceSansBold; --The font of the text
        FontSize = Enum.FontSize.Size24; --The size of the text
    })
end)

game.Players.ChildAdded:connect(function(player) --Event that fires when player joined
    if not pcall(function() --If the pcall() function was not called
        game.StarterGui:SetCore("ChatMakeSystemMessage", { --Gets the chat
            Text = "[Server]:  " ..player.Name .. " has joined the game!"); --Sets the text
            Color = Color3.new(255,255,255); --Sets the color of the text
            Font = Enum.Font.SourceSansBold; --Sets the font of the text
            FontSize = Enum.FontZise.Size24; --Sets the size of the text
        })
    end)      then
        print("Error") --prints error if the pcall() function was not called
    end
end)

game.Players.ChildRemoved:connect(function(player) --Event that fires when player left
    if not pcall(function() --if the pcall() function was NOT called
        game.StarterGui:SetCore("ChatMakeSystemMessage", { --Gets the chat
            Text = "[Server]:  " ..player.Name .. " has left the game!"); --Sets the text
            Color = Color3.new(255,255,255); --Sets the color of the text
            Font = Enum.Font.SourceSansBold; --Sets the font of the text
            FontSize = Enum.FontZise.Size24; --Sets the size of the text
        })
    end)      then
        print("Error") --prints error if the pcall() function was not called
    end
end)

For more information, visit this link: http://wiki.roblox.com/index.php?title=API:Class/StarterGui/SetCore

If this helped you out, make sure you accept the answer!

0
You don't have to use the ChildAdded and ChildRemoved event on the Players service, just use PlayerAdded and PlayerRemoving :P Valatos 166 — 8y
0
I know, this was just as an example. The script itself does the same thing. nanaluk01 247 — 7y

Answer this question