Delete specific ImageLabel

  1. What do you want to achieve?

I am trying to add a thumbnail if a player hits a part and if he leaves the part.
I want it to delete the thumbnail that the player made.

  1. What is the issue? Include screenshots / videos if possible!

Making the thumbnail is working and deleting works also. with 1 player.
If 2 players hit the part it shows 2 thumbnails. but it looks like player 2 deletes player 1’s thumbnail.
I Made the thumbnail.name the name of the player who adds it.
Is this the right way? or should i use the userId?
And how do i get the right thumbnail to be deleted?


local queuePart = workspace.TenPlayers.QueuePart
local panel = workspace.TenPlayers.Panel.SurfaceGui.Frame
local StartP1 = workspace.TenPlayers.Start.StartP1
local StartP2 = workspace.TenPlayers.Start.StartP2
local StartP3 = workspace.TenPlayers.Start.StartP3
local StartP4 = workspace.TenPlayers.Start.StartP4
local StartP5 = workspace.TenPlayers.Start.StartP5
local StartP6 = workspace.TenPlayers.Start.StartP6
local StartP7 = workspace.TenPlayers.Start.StartP7
local StartP8 = workspace.TenPlayers.Start.StartP8
local StartP9 = workspace.TenPlayers.Start.StartP9
local StartP10 = workspace.TenPlayers.Start.StartP10
local Queue = {}
local MinQueue = 1
local MaxQueue = 10
local playersInQueue = workspace.TenPlayers.playersInQueue
local queueClosed = workspace.TenPlayers.queueClosed
local alreadyExists = false

local function updateGui()
	local MinQueueValue = MinQueue - #Queue
	
	panel.StatusQueue.Text = "Wait for  at least " ..MinQueueValue..  " players and 30 sec." 
	if panel.StatusQueue.Text == "Wait for  at least 0 players and 30 sec." then
		panel.StatusQueue.Text = "Game starts with " ..#Queue.. " players and 30 sec."	
	end
	panel.QueueLabel.Text = "Players in Queue: " ..#Queue.. " /" ..MaxQueue
end

local function Teleport(player, position)
	player.Character.HumanoidRootPart.CFrame = position.CFrame
end

local function onPartTouched(touchingPart)
	local humaniod = player.Parent:FindFirstChildWhichIsA("Humanoid")
	if touchingPart.Name == "UpperTorso" then
		wait(1)
		
		for i=1,#Queue do
			if Queue[i] == player then
				alreadyExists = true
			end
		end

		if alreadyExists == false then
		
			if playersInQueue.Value < MaxQueue then
				table.insert(Queue, player.Parent)
				playersInQueue.Value = playersInQueue.Value + 1
				print(Queue)
				updateGui()
				
				
				local plr = game.Players:GetPlayerFromCharacter(player.Parent)
				local userId = plr.userId
				local thumType = Enum.ThumbnailType.AvatarBust
				local thumSize = Enum.ThumbnailSize.Size48x48
				local content = game.Players:GetUserThumbnailAsync(userId, thumType, thumSize)
				local newFrameImg = game.ReplicatedStorage:WaitForChild("PlayerImage"):Clone()
				newFrameImg.Image = content
				newFrameImg.Position = UDim2.new(newFrameImg.Position.X.Scale + (0.1 * #game.Workspace.TenPlayers.Panel.SurfaceGui.Queue:GetChildren()), 0, 0, 0)
				newFrameImg.Name = plr.Name
				newFrameImg.Parent = game.Workspace.TenPlayers.Panel.SurfaceGui.Queue
			end

			if  playersInQueue.Value == MinQueue  then
		    --Start Time 30sec.
			--After timer Teleport to StartP*	
			end
			if playersInQueue.Value == MaxQueue then
				queueClosed.Value = true
			end
		end
	end
end

local function onPartTouchEnded(touchingPart)
	local humaniod = player.Parent:FindFirstChildWhichIsA("Humanoid")
	if touchingPart.Name == "UpperTorso" then	
		wait(1)
		for i=1,#Queue do
			if Queue[i] == player.Parent then
				alreadyExists = true
			end
		end
		
		if alreadyExists == true then
			local frame = workspace.TenPlayers.Panel.SurfaceGui.Queue:FindFirstChildOfClass("ImageLabel")
			for i, v in pairs(Queue) do
				if frame.Name == v.Name  and frame.Name == player.Parent.Name then
			frame:Destroy()	
					table.remove(Queue, #Queue)
					playersInQueue.Value = playersInQueue.Value - 1
					updateGui()
				end
		end	
			alreadyExists = false
		end
	print("Left Queue")
		end
end
		queuePart.Touched:Connect(onPartTouched)
		queuePart.TouchEnded:Connect(onPartTouchEnded)
	

In that case you would have to get the players thumbnail and use the :Destroy() function to remove it.

You are making things more complicated than it needs to be.

Instead of the queue system, use a local debounce for each player. This will prevent the touch triggering multiple times for each player so it has enough time to finish the first run-through.

Something like:

local debounces = {}
-- when players touch do:
if not debounces[playerName] then
      debounces[playerName] = true
     -- run the function for player
      task.wait(1)
      debounces[playerName] = false
end

Also please don’t use “player” as the variable name for the part that was touched. Doing player.Name == "UpperTorso" just looks weird lol. Simply “touchingPart” will suffice.

1 Like

any idea how i make sure it deletes the good one and not some1 else’s?

newFrameImg.Name = plr.Name 

Just check for the frame that belongs to the player that the image is for.

I’ve tried to use debounce.
But i guess i made it even more complicated. :blush:
The issue is that sometimes if i touch the queuePart, it will activate touchended… Even if my touchpart is a block where my character fits in.

local queuePart = workspace.Q2.queueTouchPart
local panel = workspace.Q2.Panel.SurfaceGui.Frame
local StartP1 = workspace.Q2.Start.StartP1
local StartP2 = workspace.Q2.Start.StartP2
local Queue = {}
local MinQueue = 1
local MaxQueue = 10
local playersInQueue = workspace.Q2.playersInQueue
local queueClosed = workspace.Q2.queueClosed
local alreadyExists = false
local debounces = {}

local function updateGui()
	local MinQueueValue = MinQueue - #Queue

	panel.StatusQueue.Text = "Wait for  at least " ..MinQueueValue..  " players and 30 sec." 
	if panel.StatusQueue.Text == "Wait for  at least 0 players and 30 sec." then
		panel.StatusQueue.Text = "Game starts with " ..#Queue.. " players and 30 sec."	
	end
	panel.QueueLabel.Text = "Players in Queue: " ..#Queue.. " /" ..MaxQueue
end

local function Teleport(player, position)
	player.Character.HumanoidRootPart.CFrame = position.CFrame
end

local function QueueTouchPart(touchPart)
wait(1)	
	local player = game.Players:GetPlayerFromCharacter(touchPart.Parent)
	if player and not debounces[player.Name] then 
		debounces[player.Name] = true
		if debounces[player.Name] == true then
			for i=1,#Queue do
				if Queue[i] == touchPart.Parent then
					alreadyExists = true
					print("Already in Queue")
				end
		end
		if alreadyExists == false then
print("Join Queue")
			if playersInQueue.Value < MaxQueue then
				table.insert(Queue, touchPart.Parent)
				playersInQueue.Value = playersInQueue.Value + 1
				updateGui()
				local plr = game.Players:GetPlayerFromCharacter(touchPart.Parent)
				local userId = plr.userId
				local thumType = Enum.ThumbnailType.AvatarBust
				local thumSize = Enum.ThumbnailSize.Size48x48
				local content = game.Players:GetUserThumbnailAsync(userId, thumType, thumSize)
				local newFrameImg = game.ReplicatedStorage:WaitForChild("PlayerImage"):Clone()
				newFrameImg.Image = content
				newFrameImg.Position = UDim2.new(newFrameImg.Position.X.Scale + (0.1 * #game.Workspace.Q2.Panel.SurfaceGui.Queue:GetChildren()), 0, 0, 0)
				newFrameImg.Name = plr.Name
				newFrameImg.Parent = game.Workspace.Q2.Panel.SurfaceGui.Queue	
			end
			if  playersInQueue.Value == MinQueue  then
				--Start Time 30sec.
				--After timer Teleport to StartP*	
			end
			if playersInQueue.Value == MaxQueue then
				queueClosed.Value = true
				end	

			end
						
		end
		task.wait(5) 
		debounces[player.Name] = false
	end			
end

local function onPartTouchEnded(touchPart)
	if alreadyExists == true then
	local player = game.Players:GetPlayerFromCharacter(touchPart.Parent)
		local frame = workspace.Q2.Panel.SurfaceGui.Queue:FindFirstChildOfClass("ImageLabel")
		
	for i, v in pairs(Queue) do
		print(frame)
			if frame.Name == v.Name then
				frame:Destroy()	
				table.remove(Queue, #Queue)
				playersInQueue.Value = playersInQueue.Value - 1
				updateGui()
			end
			alreadyExists = false
			print("Left Queue")
	end
	end
end


queuePart.Touched:Connect(QueueTouchPart)

queuePart.TouchEnded:Connect(onPartTouchEnded)