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
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"
local Player = game:GetService'Players'.LocalPlayer
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
Text = string.gsub(JoinText,"PLAYER",Player.Name);
Color = Color3.new(0,1,1);
Font = Enum.Font.SourceSans;
FontSize = Enum.FontSize.Size24;
})
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.
1 comment
Your code is perfectly fine. It needs to be a localscript. Problem...?