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

Player left server chat message not sending?

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!

1 answer

✓ Accepted answer

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)

1 comment

0

This helped perfectly, thank you! I wasn't sure how to get the event to fire properly with OnClientEvent, thank you for this! Also yes, the "PlayerLeftMessage" was a remoteevent in ReplicatedStorage. Thank you very much!

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