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

Why does this player removing function not work?

To explain a bit, players is a table, and when a player joins, it adds the player. I only get this error when removing, not in other parts of the script. The code is here:

function rem(p)
	for _, v in pairs(1, #players) do
		if p.Name == players[v] then
	table.remove(players, players[v])
	print (players[v].." left!")
	end
	end
end

It gives me the error: 21:03:17.548 - Workspace.Script:77: bad argument #1 to 'pairs' (table expected, got number) 21:03:17.550 - Stack End

1 comment

0

How are you defining players? Also, you do not need the 1, that's what's throwing the script off saying you got a number.

1 answer

✓ Accepted answer

Assuming 'players' is an array...

function rem(p)
    for _, v in pairs(#players) do -- You don't need the number for a pairs loop
        if p.Name == players[v] then
    table.remove(players, players[v])
    print (players[v].." left!")
    end
    end
end

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