Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remove name from table without knowing index number?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

0
Thank you! I didn't think about this! MezornoIV 25 — 5y
0
Just a quick side comment: I probably should have used "ipairs" instead of "pairs" vanilla_wizard 336 — 5y
Ad

Answer this question