Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help me with this player left message?

So, I made a code where if you joined message pop-up in chat that worked Ok, But how about the left message. I tried multiple times and it didn't work what's wrong with it?

This script in ServerScriptService


local MessageEvent = game.ReplicatedStorage.PlayerLeftMessageEvent

game.Players.PlayerRemoving:Connect(function(Player)
	repeat wait() until Player.Character or Player.CharacterRemoving:Wait()
 local text = "{System} "..Player.Name..", Has left to the game"
    local color = Color3.fromRGB(255,0,0)
	    local font = Enum.Font.Cartoon
   MessageEvent:FireAllClients(text,color,font)	
end)


What wrong with that's it's not working??

This for StarterGUI

local StarterGui = game:GetService("StarterGui")
local MessageEvent = game.ReplicatedStorage.PlayerLeftMessageEvent

 
MessageEvent.OnClientEvent:Connect(function(text,color,font)
    StarterGui:SetCore("ChatMakeSystemMessage",{
        Text = text,
        Color = color,
        Font = font
    })
end)

2 comments

0

Please, give us the error!

0

It doesn't appear any errors in Scrpit Analysis or logs what do i do?

2 answers

✓ Accepted answer

You can delete the server script and the event, this is a 100% client script

local SG = game:GetService("StarterGui")
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(Player)
	SG:SetCore("ChatMakeSystemMessage", {
		Text = "{System} "..Player.Name.." has left the game",
		Color = Color3.fromRGB(255,0,0),
		Font = Enum.Font.Cartoon
	})
end)

This detects the player removing on the client. Keep in mind this won't work if a player gets disconnected from the game.

On line 4, you put:

repeat wait() until Player.Character or Player.CharacterRemoving:Wait()

Your script is probably waiting infinitely here, hence why any of the code isn't running.

You don't really have to put this line into your code, as once the player removes they're essentially already removed from the game. There is no point in calling the character after.

This discussion is preserved as it was. New answers, comments, and votes are closed.