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

Why will it not scan workspace for anything in the virus chest variable?

Asked by 5 years ago

hi im wondering why this wont work, and if this is a bad slow way to do it, tell me. im making a anti virus plugin READ on bottom to see attempt to fix it by a previous question. main code that is probleming:

1local w = workspace:GetDescendants()
2    for i = 1, #VirusChest do
3        if w[i].Name == #VirusChest then
4            w[i].Parent = newFolder3

variables:

001local VirusChest = {
002    "join teh moovment!";
003    "Kill tem!";
004    "StockSound";
005    "Deth 2 teh samurai!";
006    "OHAI";
007    "OH SNAP YOU GOT INFECTED XD XD XD";
008    "No samurai plzzz";
009    "4D Being";
010    "Virus";
011    "4dbeing";
012    "4d being";
013    "loser";
014    "infected";
015    "rolf";
View all 101 lines...

srry i had to rush it, pls help comment if u have questions

Also, trying to change to these as well, did not work:

for i, v in pairs(VirusChest) do

and

if w[i].Name == VirusChest[i] then

1 answer

Log in to vote
1
Answered by
compUcomp 417 Moderation Voter
5 years ago
Edited 5 years ago

Edit: So sorry! I wasn't thinking. Try this:

1local w = workspace:GetDescendants()
2for i = 1, #w do
3    for j = 1, #VirusChest do
4        if w[i].Name == VirusChest[j] then -- here was the problem (my problem and your problem)
5            w[i].Parent = newFolder3

I wish there was a more efficient way to do it but sadly I cannot think of one.

Original: You are checking if anything in the workspace has a name that is equal to the number of things in your virus chest. You want to check if the name is equal to the current iteration.

1local w = workspace:GetDescendants()
2for i = 1, #VirusChest do
3    if w[i].Name == VirusChest[i] then -- here was the problem
4        w[i].Parent = newFolder3
0
Sorry to put u down, but if u read the whole thing I said i already tried something similar to this. I understand where the problem is. but replacing my code with that and making sure there's no silly errors, i get attempt to index nil with 'Name' RobloxGameingStudios 145 — 5y
0
its on line 3, sad isnt it of ur code RobloxGameingStudios 145 — 5y
0
I want to warn you that it is *very slow*. It is iterating (#VirusChest * #w) times. Stick a wait somewhere so studio doesn't crash compUcomp 417 — 5y
Ad

Answer this question