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

Remove name from table without knowing index number?

I need help with sending information on a player. I'm making a game where it is crucial for the server to know if you've died or not, and I'm trying to send a RemoteEvent from the client to the server to remove the client user's name from the table of alive players. I don't know how I can do this, because table.remove() requires you know the index number, and not the value of the index.

1 answer

✓ Accepted answer

If you don't know the index number, you can check if the value (v) is what you're looking for and then use index i.

local alivePlayers{
	"Shedletsky", "builderman", "alvinbloxx", "Sorcus"
}

-- builderman died but I don't know where he is in the table

local function removeDeadPlayer(name)
	for i,v in pairs(alivePlayers) do
		if v == name then -- is the value at this index what you're looking for?
			table.remove(alivePlayers, i) -- number "i" notes the index
		end
	end
end

removeDeadPlayer("builderman")

something like that

if this helped you please mark it correct, if you have questions please comment below <3

2 comments

0

Thank you! I didn't think about this!

0

Just a quick side comment: I probably should have used "ipairs" instead of "pairs"

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