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

How would I make the server say '[Server] Hello playername!' in the chat?

Asked by 8 years ago

I tried too, but it does not work..

game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
    Text = "Welcome to my game!"; --This is a required field, it will allow you to set the message to any string you want.
    Color = Color3.new(0,1,1); --This is optional, it will allow you to add a custom color to the chat, however will default to Color3.new(255/255, 255/255, 243/255) if not set.
    Font = Enum.Font.SourceSans; -- Optional, defaults to Enum.Font.SourceSansBold --This is optional, this field will allow you to change the font of the text to any of the current 7 fonts you want.
    FontSize = Enum.FontSize.Size24; -- Optional, defaults to Enum.FontSize.Size18 --This is once again optional, and you can change it to any of the existing sizes.
})
0
Your code is perfectly fine. It needs to be a localscript. Problem...? Shawnyg 4330 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

There are a few ways you could do this, but there's one thing we should understand. Assuming we don't want the chat to have your server message appear every time the player respawns, we can do this one of two efficient ways:

1) Using RemoteEvents and the PlayerAdded event w/ server script

This method would include having a server script manage an event listener with the client, so using the FireClient on the new player that joined the game (also establishing an OnClientEvent within a local script of the player), then having that chat system notify the individual.

However, this may seem complicated if you've never worked with RemoteEvents before. This method would be purely for personal preference, or if you wanted to handle some other intricate procedure as the player joins. Here are some sources demonstrating how this client / server system works with remote events:

Custom chat - My old video: https://www.youtube.com/watch?v=uoUfrm9ZUbI

Notifying all players with a GUI - SH answer: https://scriptinghelpers.org/questions/25370/how-to-send-a-notification-to-all-players-via-gui#28942

Both of these sources explain how to create a system interchangeably between OnServerEvent, and OnClientEvent.

Here's a bit of an example on how this could work:

Server script

local Remote = game:GetService'ReplicatedStorage':WaitForChild'RemoteEvent'
local Players = game:GetService'Players'

Players.PlayerAdded:connect(function(Player)
    Remote:FireClient(Player,'Notify','[Server]: Hello '..Player.Name)
end)

Local script

local Remote = game:GetService'ReplicatedStorage':WaitForChild'RemoteEvent'
local Players = game:GetService'Players'

Remote.OnServerEvent:connect(function(Request,Value)
    Request = Request:lower()
    if Request == 'notify' then
        -- Your code here
    end
end)

I'm not gonna make a complete local script example, since the rest is pretty self explanatory, and is good practice for you if you've never worked with remotes before.

2) Using ReplicatedFirst, w/ a local script

A simpler way to go about something like this, could be putting a local script in the ReplicatedFirst service, and then set up your server message. Let's assume we'll go about using this method, since it's a shorter, more to-the-point answer.

First

Putting the local script in the service. Here's where we're at: http://prntscr.com/abc1zi

Second

The method you used to send the notification to the default chat, is correct. All you have to do is use some simple string concatenation with the information of your choice. If you don't know what string concatentation is, I suggest visiting this: http://wiki.roblox.com/index.php?title=Concatenation

Now our code should look something like this:

local JoinText = "[Server]: Hello PLAYER" -- we're going to use string.gsub to replace the *player* with the name of the player.

-- Get the local player
local Player = game:GetService'Players'.LocalPlayer

game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
    Text = string.gsub(JoinText,"PLAYER",Player.Name); -- Replace "PLAYER" with the local player's name.
    Color = Color3.new(0,1,1); 
    Font = Enum.Font.SourceSans;
    FontSize = Enum.FontSize.Size24; -- Optional, defaults to Enum.FontSize.Size18
})

This same concept can be done with StarterPlayerScripts instead of ReplicatedFirst as well.

I strongly recommend you check out how string manipulation and string concatenation works if you are to understand this any better. Here's a source for string manipulation: http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation

Hope this helped, let me know if you have any questions.

0
Long explainment for no reason. You could just place his code in a localscript and place it in StarterPlayerScripts under StarterPlayer. That's what I did for my game and it works. Thundermaker300 554 — 8y
1
I like to execute multiple possibilities to give the asker a better understanding of what they're working with along with giving them new ideas ScriptGuider 5640 — 8y
Ad

Answer this question