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

Better way to get parts from workspace and faster?

Asked by 4 years ago
Edited 4 years ago

So I was working with a script that uses getdescendants() and I noticed that it takes a while to go through workspace and find the parts with the exact name I want to find when there are other models and parts in workspace. I don't really know how to explain it properly but I don't want the script to find the parts I want slowly. The parts I'm trying to find have a certain name to them and are also in different models and places which is why I'm using getdescendants(). Sorry if this doesn't make sense :(

while true do
    if script.Parent.TGL.Value == 1 then -- this is just a int value set to 1 named TGL
        for i,v in pairs(game.Workspace:GetDescendants()) do 
            if v.Name == "Part1" then -- checks the name of the part
                local distance = (script.Parent.Position-v.Position).magnitude
                if distance <= 1000 then -- checks the distance
                    print(v.Name.." is close to "..script.Parent.Name) -- prints if it is close
                    wait()
                end
                wait()
            end
            wait()
        end
        wait()
    end
    wait()
end
0
Try removing the wait() statements, unless they serve a certain purpose. gskw 1046 — 4y
0
I have always had this issue to when trying to make a anti-virus plugin, check it out here: https://www.roblox.com/library/3499696546/Ro-Protect-1-11 RobloxGameingStudios 145 — 4y

Answer this question