****I was working on a script to when a player leaves the server it will say the player has left server on the chat. But as soon as I join the server, it says that.
01 | local Players = game:GetService( 'Players' ) |
02 |
03 | function onPlayerRemoved(player) |
04 | game:GetService( 'StarterGui' ):SetCore( 'ChatMakeSystemMessage' , { |
05 | Text = ( 'Server| ' .. player.Name .. ' has left the game.' ); |
06 | Color = Color 3. new(. 9 ,. 5 ,. 05 ); |
07 | Font = Enum.Font.SourceSansBold; |
08 | FontSize = Enum.FontSize.Size 18 ; |
09 | } ) |
10 | end |
11 |
12 | Players.PlayerRemoving:connect(onPlayerRemoved) |
13 |
14 | for _,player in pairs (Players:GetPlayers()) do |
15 | onPlayerRemoved(player) |
16 | end |
Lines 14-16 do nothing but call the function as soon as the script runs.
Fix,
Remove the extra lines of code,
01 | local Players = game:GetService( 'Players' ) |
02 |
03 | function onPlayerRemoved(player) |
04 | game:GetService( 'StarterGui' ):SetCore( 'ChatMakeSystemMessage' , { |
05 | Text = ( 'Server| ' .. player.Name .. ' has left the game.' ); |
06 | Color = Color 3. new(. 9 ,. 5 ,. 05 ); |
07 | Font = Enum.Font.SourceSansBold; |
08 | FontSize = Enum.FontSize.Size 18 ; |
09 | } ) |
10 | end |
11 |
12 | Players.PlayerRemoving:connect(onPlayerRemoved) |
Sometimes thing are simple, and that should be the right answer.
Good Luck!