Hey there! I have a perfectly working and more complicated join script that sends a message when the player enters, but I cannot get it to work when I simplify it and try to rewrite it to send a message when the player leaves! This is the script I have for when the player leaves the game (in StarterGui) :
textColor = BrickColor.new("Br. yellowish orange") game.ReplicatedStorage.PlayerLeftMessage.OnClientEvent:Connect(function(player) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = player.Name..' has disappeared'; Font = Enum.Font.SourceSansBold; Color = textColor.Color; FontSize = Enum.FontSize.Size24; }) end)
It connects to a event in ReplicatedStorage that should be detected by the player leaving. I'm not quite exactly sure what's wrong as I can't get it to work. Meanwhile I got my player join message to work. Player join message is here below incase it is affecting this new script
Player join message's StarterPlayerScripts script :
local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild('RemoteEventJoin') textColor = BrickColor.new('Cyan') local function welcome(playerName) game.StarterGui:SetCore('ChatMakeSystemMessage', { Text = playerName..' has joined'; Font = Enum.Font.SourceSansBold; Color = textColor.Color; FontSize = Enum.FontSize.Size24; }) end remoteEvent.OnClientEvent:Connect(welcome)
And here is the accompanying script in ServerScriptService for the join message as well :
local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild('RemoteEventJoin') local function onPlayerJoin(player) remoteEvent:FireAllClients(player.Name) end game.Players.PlayerAdded:Connect(onPlayerJoin)
I'm unsure how to rewrite the "join message" script to work for leaving players, which is why the "leaving players" script is less intact than the join players script. Thank you to anyone who reads!
from the leave player script, i can imagine there is another remoteevent for the leave script i could be missing something, however
serverscriptservice script
local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild('RemoteEventJoin') local remoteEvent2 = ReplicatedStorage:WaitForChild('PlayerLeftMessage') local function onPlayerJoin(player) remoteEvent:FireAllClients(player.Name) end local function onPlayerLeave(player) remoteEvent2:FireAllClients(player.Name) end game.Players.PlayerAdded:Connect(onPlayerJoin) game.Players.PlayerRemoving:Connect(onPlayerLeave)
startergui leave script
local ReplicatedStorage = game:GetService('ReplicatedStorage') local remoteEvent = ReplicatedStorage:WaitForChild('PlayerLeftMessage') textColor = BrickColor.new("Br. yellowish orange") local function goodbye(playerName) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = playerName..' has disappeared'; Font = Enum.Font.SourceSansBold; Color = textColor.Color; FontSize = Enum.FontSize.Size24; }) end remoteEvent.OnClientEvent:Connect(goodbye)