I have this script that runs system messages at different times. If I put it in a local script, each player gets it at a different time, but if I put it in a normal script, it doesn't work at all. Is there anyway to fix this? Here is the script: It gives this error when its in a normal script. https://gyazo.com/bad11f3082d741c6e5fe9290a7b9c740
01 | game.Players.PlayerAdded:connect( function (player) |
02 | wait() |
03 | while true do |
04 | if game.Workspace.PlayerCount.Players.Value < = 5 |
05 | then |
06 | game.StarterGui:SetCore( "ChatMakeSystemMessage" , { |
07 | Text = "Waiting for at least FIVE players to join.." , |
08 | Color = Color 3. new( 100 , 100 , 0 ), |
09 | Font = Enum.Font.SourceSansLight, |
10 | FontSize = Enum.FontSize.Size 18 , |
11 | print ( "made it here lol" ) |
12 | } ) |
13 | wait( 10 ) |
14 | end |
15 |
One way you could do this is to use RemoteEvents
. Start by inserting a RemoteEvent
into ReplicatedStrorage
. Next create a script inside of Workspace
or ServerScriptService
and reference the RemoteEvent
: Note All the code below is untested
1 | local RemoteEvent = game:GetService( "ReplicatedStorage" ).RemoteEvent |
You could then check if something has happened in the game. Note: It must be something to do with all players so that when this becomes true they will all see the message at the same time. After the condition is true you can fire it to the client
Here is an example:
01 | local RemoteEvent = game:GetService( "ReplicatedStorage" ).RemoteEvent |
02 | local Toggle = false |
03 |
04 | while true do |
05 | Toggle = true |
06 | wait( 120 ) |
07 | Toggle = false |
08 | end |
09 |
10 | while wait( 0.1 ) do |
11 | if Toggle then |
12 | RemoteEvent:FireClient() |
13 | end |
14 | end |
Now it's time to edit your LocalScript
. You can use the RemoteEvent
in the same way a normal event is used. Instead of PlayerAdded
for instance you would type OnClientEvent
(For the client):
1 | local RemoteEvent = game:GetService( "ReplicatedStorage" ).RemoteEvent |
2 |
3 | RemoteEvent.OnClientEvent:Connect( function () |
4 | --Message stuff |
5 | end ) |
One other problem is that when you connected your PlayerAdded
event you used connect not Connect
. Hopefully this help!