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

Using SetCore in the server?

Asked by 8 years ago

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?

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

In order to have a server send a message across to all clients, you would need the following.

  • Local Script
  • Server Script
  • RemoteEvent

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.


Hopefully this answered your question, if it did do not forget to hit the accept answer button. If you have any questions feel free to comment below.
0
When testing this in Studio it works, but when testing it in a server it does not. NewVoids 97 — 8y
0
Would you mind making another question and explain all you are doing? Where the scripts are and where the RemoteEvent is located? Even errors in the Developer Console. M39a9am3R 3210 — 8y
Ad

Answer this question