✓ Accepted answer
Well one thing we have to keep in mind here, is that the rawset function is doing nothing (in this case). If this is indeed all the code behind this program, and there's no other point in time where a metatable is set to it with a __newindex metamethod, there's literally no point in having it. So that narrows down our code to this:
Selected = {}
function CleanSelected()
for i,v in pairs(Selected) do
if v == nil or v:findFirstChild("Torso") == nil then
Selected[i] = Selected[i+1]
end
end
end
What it's doing?
First off, the first condition of the if statement if v == nil is redundant. nil values are automatically accounted for as something that doesn't exist, so the iteration will not even register it's variable's existence (thus, making the comparison pointless).
Other than that, all this code is doing is checking whether or not a torso exists inside v, and if it doesn't, then it assigns the table the next value in it's storage.
Suggestion?
Whether or not you're actually going to be using this code, or if you were just looking at random stuff and had a question, it can't hurt to clean this up a bit:
local Selected = {}
local function CleanSelected()
for i = 1,#Selected do
local v = Selected[i]
local torso = v:FindFirstChild("Torso")
if not torso then
Selected[i] = Selected[i+1]
end
end
end
Hope that helped, let me know if you have any questions.
2 comments
Checking for the existance of
vis actually valid asvnot havingFindFirstChildas a member causes an error in that code.Actually, no, now I understand what you meant.
vcannot be nil in a generic for loop...