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

Removing a players name from Table?

So basically what I have is a script for a scrolling frame, and when it is opened, it lists all the players in the game except for player that carries the script. I've added all the players into a table, and I've run a loop so that for how many players are in the game, a new frame will be there and visible with the players name on it

For some reason this block of code is not working, I've run print on both variables to see specifically if they do equal each other, which they do when the loop runs through the table and gets the player who ones the scripts name, but for some reason it's not running the if part of the the if else statement

if players[countertwo] == playerName then
		table.remove(players, countertwo)	
		countertwo = countertwo + 1				
_G.Selected = 0
local frame = script.Parent.ScrollingFrame
local counter = 0
local textboxes = script.Parent.ScrollingFrame:GetChildren()
local players = game.Players:GetChildren()
local frames = #players
local playerName = script.Parent.Parent.Parent.Parent.Parent
local countertwo = 1

function onItemSelected(item)
	
	_G.itemSelected = item
end


function onMouseButton1Down()
	
	if _G.Selected == 0 then
		frame.Visible = true
		while countertwo <= frames do	
			if players[countertwo] == playerName then
				table.remove(players, countertwo)	
				countertwo = countertwo + 1				
			else		
				frame:FindFirstChild(tostring(textboxes[countertwo])).Name =
tostring(players[countertwo])
				frame:FindFirstChild(tostring(players[countertwo])).Visible = true	
				frame:FindFirstChild(tostring(players[countertwo])).Name = tostring(players[countertwo])
				frame:FindFirstChild(tostring(players[countertwo])).Text = tostring(players[countertwo])
				countertwo = countertwo + 1		
			end
			
		
		end	

1 answer

✓ Accepted answer

I believe I've found the answer myself, it seems like Roblox was not not running the if statement for some reason but I waited a bit and reopened a test server with two test clients and it worked, I also figured out that in the

 if players[countertwo] == playerName then
                table.remove(players, countertwo)  
                countertwo = countertwo + 1 

I had, the countertwo should be taking away one instead of adding one to the counter, because the it is removing a player and so it shouldn't add a frame for that player

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