Identifying the name of a GUI element as a players' username

Hey! :wave:

I need help with identifying the name of a GUI element so I can destroy it for all players. The thing is, the GUI names itself to the username of the player who triggered the remoteevent which made the GUI create itself, so now I’m trying to make it destroy for all players when clicked through a remoteevent. How would I reference the GUI element to destroy it for all players? The scripts I currently have are below, let me know if you have any questions regarding it or are confused. Thanks for trying to help! :hearts:


		if Message == "!pts" then


local player = game.Players.LocalPlayer
local frameclone = player.PlayerGui.PTSDisplayer.HolderFrame.SampleFrame:Clone()
frameclone.Parent = script.Parent.HolderFrame
frameclone.Visible = true
frameclone.Text = PTSName.." has requested PTS!"
frameclone.Name = PTSName
1 Like

@Jackscarlett Could you help with this? :eyes:

Bumping again, I’m not sure why I’m not getting a response.

It’s only been half an hour! Also, you never actually asked a question in your post so it’s sort of hard to give an answer :slight_smile:

Edited it, thanks. (30 ch@rssss)

When one player clicks it, send a remote event to the server. Then fire all clients in a remote event and when they receive it, code it to destroy it. I have code for this below.

No need to give Player.Name as a parameter.

Not required here

This is actually the player instance and not just the name.

To solve your actual question.

Using the MouseButton1Click event you can fire a remotevent and handle it on server, which fires another remote event and handle it on the client to Destroy the guis you want! (using FireAllClients())

Button Code:

button = --put whatever text button or thing here
remote = --put the remote event path here (create it beforehand)


Server code:

remote = --same remote path as above


Client Code:

gui = --put the gui to destroy here
remote = --same remote as before

    gui = nil

You will want to add verification to prevent exploits but you said it is urgent so that can be done later i suppose.

This would be in addition to the code you sent (I am not 100% sure what the code you sent is for…)

EDIT: gtg now so I wont respond any more, hope this helps!

The thing is… I can’t reference the name of it as the name of it changes to the name of the player who triggers the very first remoteevent to fire, so I need to reference the name of the gui element to destroy it which is what I need help with.

The thing is… I can’t reference the name of it as the name of it changes to the name of the player who triggers the very first remoteevent to fire, so I need to reference the name of the gui element to destroy it which is what I need help with. :heart:


local PTSReq ="RemoteEvent")
PTSReq.Name = "PTSReq"
PTSReq.Parent = game.ReplicatedStorage


local CurrentPassword = nil
local cooldown = 3
local dbg = false

PTSReq.OnServerEvent:Connect(function(Player, Password)
	if Password ~= CurrentPassword or CurrentPassword == nil then
		Player:Kick("Security Violation")
		PTSReq:FireAllClients("", 1)
		dbg = false

	if #game.Players:GetPlayers() <= 1 then return end
	if dbg then return end
		if msg:lower():sub(1, 4) == "!pts" then
			dbg = true
			CurrentPassword = math.random(-2048, 2048)
			PTSReq:FireAllClients(Player.Name, 0, CurrentPassword)


local GuiInstances = {}

local PTSReq = game.ReplicatedStorage:WaitForChild("PTSReq")

PTSReq.OnClientEvent:Connect(function(Name, RequestType, Password)
	if Name == game.Players.LocalPlayer.Name then return end
	if RequestType == 0 then
		local Gui = script.Gui:Clone()
		table.insert(GuiInstances, Gui)
		Gui.Main.TextLabel.Text = Name.." has requested pts."
		Gui.Parent = game.Players.LocalPlayer.PlayerGui
	elseif RequestType == 1 then
		for i,v in pairs(GuiInstances) do
			pcall(function() v:Destroy() end)

Test Place (Test with multiple clients):
Test.rbxl (35.9 KB)

Just to clarify, which one is the GUI element?

It will not provide the Local Player…

Remote Functions and Events (

RemoteEvent:FireAllClients (

Ooop didn’t research enough before answering, I rarely use FireAllClients, my bad. Thanks for pointing it out.

Could I have a script for that? Sorry!

The name of it is the username of the player who said “!pts” which fired the remoteevent.

This is too advanced for me and I don’t want a whole rewrite of the script, I simply just want to know how to reference the GUI element as it’s the player who said ‘!pts’ and triggered the remoteevents’ username.

It is simple… read it and you will learn from it

here is an explanation:

player types in the command, server sends info to all clients stating the username of the player who said the command, the number 0 and a random number for the password

the clients check the number and see that it is 0, so the clients create a gui and use the username for the text, then when the gui is clicked by the client, the client sends the password back to the server

the server checks the password, and if it is correct it sends back to all the clients the number “1”, the clients see that they received a 1 and delete all the GUIs they have created in regards to the script ( it knows which GUIs to delete cause they are added to a table on creation)

Alright, hmm.
I’m still confused by the case here.

  1. What is everything that is supposed to happen when you a player typed in the message “!pts”?
  2. What didn’t happen or results in error?

I tried the test game and it didn’t work.