Player left event wont change the text of a text label

When the player leaves, I want it to display temporarily as a text label on the screen.

The issue is, when I run this code

function writeLog(player)
	game.StarterGui.PlayerLeft.LeftText.Text = player.Name.."left the game"


it doesn’t do anything.

No errors either.

(Server Script in ServerScriptService)

It the lowercase c in connect intentional? Did you use a uppercase c in the real code?

This is obvious, that you haven’t changed the correct visible label. The StarterGui is not what is displayed, but replicated to the player’s GUI. You need to fire a signal to all players and let their LocalScript handle the change.

One more thing, how could I pass the player that left’s name to the local script, without setting it to the client’s name?

I think you should use remote events/remote functions

In this case you could use a remote event that fires to every client to update the label in every player’s screen.

The GUI from StarterGui clones to PlayerGui when the player joins so in this case you should be updating PlayerGui which only can be done from the client.

Hello there! If you want to temporarily display a text label on the screen, you’ll have to use a RemoteEvent. Whenever someone left, you must call the RemoteEvent via a server script.

Create a script in ServerScriptService:
This script will call the RemoveEvent whenver a player left the game.

game.Players.PlayerRemoving:Connect(function(Player) --When someone left the game...
	game.ReplicatedStorage.RemoteEvent:FireAllClients(Player.Name) --... call the RemoteEvent

Then, create a local script into StarterGui:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Player) -- When the RemoteEvent is being called...
	script.Parent.PlayerLeft.LeftText.Text = Player .."left the game" --Change the text.
-- Change this to wherever your TextLabel is.

I hope this helped you, feel free to reply to this post of you has any questions!

I am getting the error “Unable to cast value to Object”

Which line is the error coming from?


Its in line 2 of the server script

You must change this line to:


:wink: This line will call the RemoveEvent for all players, Player.Name is just an argument, not an player object.

Edit: The script I posted above wasn’t working, but it is now! I just made a little mistake.

You need to send the Player, not Player.Name

This time, no errors. But nothing changes. I think we need to change the gui in LocalPlayer.PlayerGui.

Could I please see where your local script is?


Alright. To fix the issue, please move ChangeGui into LeftText and edit the local script to:

game.ReplicatedStorage.LeftEvent.OnClientEvent:Connect(function(Player) -- When the RemoteEvent is being called...
	script.Parent.Text = Player .." left the game"
1 Like

It can be lowercase or uppercase.