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

How to remove an object from a table?

Asked by
Hydrogyn 155
4 years ago
Edited 4 years ago

hello,

I want to remove the LocalPlayer from the table so the code after I removed the player won't affect the LocalPlayer aswell.

while wait() do
    for a,b in pairs(game.Players:GetPlayers()) do
        if b.Name == game.Players.LocalPlayer.Name then
            table.remove(game.Players:GetPlayers(),1)       
        end
    end
end

The only trouble I'm having is how do I know what number position is the LocalPlayer?

1 answer

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago
while wait() do
    for a,b in pairs(game.Players:GetPlayers()) do
        if b.Name == game.Players.LocalPlayer.Name then
            table.remove(game.Players:GetPlayers(),a) 
            --a is the index, it shows what number the loop is at.     
        end
    end
end
Ad

Answer this question