Lobby queue enters my username as all of the players

for i, v in pairs(Lobby.Gradient.Slots:GetDescendants()) do
                if v:IsA("TextLabel") then
                    if v.Text == "N/A" and not table.find(PeopleInLobby, player.Name) then
                        table.insert(PeopleInLobby, player.Name)
                        v.Text = player.Name
                    end
                end
            end

so a player enters a region and a script detects it
it makes a lobby queue and inserts the player into a table and changes a text label to the player’s name
i have five text labels
when i tested it, all the text labels were named after my username
i only wanted it to have one text label after myself
how would i fix that?

Your issue here, is that the loop will look through all the available Text Labels a single time, and since it will not find Player.Name in each new one, it will do it to all of them. Your solution is to break the loop after the v.Text = Player.Name code

If you’re running a loop that won’t typically end, such as an infinite while — do loop, you can force it to end with the break command so the script can continue running the code following it:

even if i add a break to it
it still puts all of the text labels as my name

local RegionPart = script.Parent

local Lobby = RegionPart.Parent

local Position1 = RegionPart.Position - (RegionPart.Size / 2)
local Position2 = RegionPart.Position + (RegionPart.Size / 2)

local Region = Region3.new(Position1,Position2)


while true do
	wait()
	
	local PartsInRegion = workspace:FindPartsInRegion3(Region, nil, 1000)
	
	for i, part in pairs(PartsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") then
			
			local character = part.Parent
			local player = game.Players:GetPlayerFromCharacter(character)
			
			local PeopleInLobby = {}
			
			for i, v in pairs(Lobby.Gradient.Slots:GetDescendants()) do
				if v:IsA("TextLabel") then
					if v.Text == "N/A" and not table.find(PeopleInLobby, player.Name) then
						table.insert(PeopleInLobby, player.Name)
						v.Text = player.Name
						break
					end
				end
			end
			for i, v in pairs(PeopleInLobby) do
				print(v)
			end end 
		end
	end

here’s my script if you need it for solution

you can use a kind of “debounce”:

local nameIsDisplayed = false

for i, v in ipairs(Lobby.Gradient.Slots:GetDescendants()) do
    if v:IsA("TextLabel") then
		if v.Text == "N/A" and not table.find(PeopleInLobby, player.Name) and not nameIsDisplayed then
			table.insert(PeopleInLobby, player.Name)
			v.Text = player.Name
			nameIsDisplayed = true
		end
	end
end

idk

I figured out the isse. You are continually checking the parts that are descendants of the LobbyPart. Then when you find one with a humanoid, which will continually be every single player that moves onto that lobby part, you do your code. The solution to this is to add the player name of the humanoid to a table that is OUTSIDE the while true do wait() loop. Then you can check to make sure that player isn’t already in there. Because as you do it now, the table resets itself each time a humanoid moves through the area.

3 Likes