In my game, the server tells tips to the player every few minutes. However, with SetCore you can only use it in local scripts, which means if I wanted the server to send a message to all the players, I couldn't.
How would I do this?
In order to have a server send a message across to all clients, you would need the following.
Remote Events are a prefered way to communicate from server to client and vice versa. Commonly this object is used for FilteringEnabled games as clients can not affect the server in any way.
You would want to set up your Remote Event with a unique name, otherwise exploiters could mess with your game if it is default. In the server script you will want to use the function FireAllClients()
, this is basically looping through all the players and using FireClient()
but much simpler. Within your LocalScript you want something to listen to the RemoteEvent, which would be the OnClientEvent
event. Whenever FireClient
or FireAllClients
is fired by the server, the RemoteEvent will send out a signal to affected players and trigger the OnClientEvent
event.
In your Server Script, you should have something like this:
game.Workspace.Messenger:FireAllClients('Hello players of the game!') --There can be as many parameters as you want. If you are using FireClient, the first parameter must be the player you want to target.
In the Local Script, you should account for all the parameters you will be receiving and modify it to your needs. Your end script may look like this.
game.Workspace.Messenger.OnClientEvent:connect(function(ServerSaid) game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{ Text = ServerSaid; -- Required. Has to be a string! Color = Color3.new(0,1,1); -- Cyan is (0,255/255,255/255) -- Optional defaults to white: Color3.new(255/255, 255/255, 243/255) Font = Enum.Font.SourceSans; -- Optional, defaults to Enum.Font.SourceSansBold FontSize = Enum.FontSize.Size24; -- Optional, defaults to Enum.FontSize.Size18 }) end)
When you try and connect the client to the server, you would want to use the FireServer()
function in a Local Script and the OnServerEvent
event in the Server Script. When using the OnServerEvent
event the first parameter will always be the player who sent the signal.