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

Script takes a while to detect another part, how do I make it faster?

Asked by 5 years ago

This script is inside a part that detects other parts and see's whether or not the name of the part it's detecting is valid. If the part's name is valid then it will be unanchored and fall through the map. What I'm trying to do is make the script not have any delays when detecting the parts so it'll just check any part and unanchor it quickly. I'm not sure what to do now but if anyone has any suggestions I would really appreciate!

local childList = {}
local Min = 0
while true do
function checkObject(obj)
    if (obj ~= script.Parent) and (obj.Name == "Breakable")  then
            table.insert(childList,obj)
elseif (obj.className == "Model") or (obj == workspace) then
        local child = obj:GetChildren()
        for x = 1, #child do
            if child[x].ClassName == "Model" then
                checkObject(child[x])
            elseif child[x].Name == "Breakable" then
                table.insert(childList,Min,child[x])
            end
        end
        obj.ChildAdded:connect(checkObject)
    end
    end
checkObject(workspace)
    if Min < #childList then
    Min = Min + 1
    wait()
    else
        Min = 1
        wait()
    end
    local child = childList[Min]
    if (child ~= script.Parent) then
        local dis = (child.Position-script.Parent.Position).magnitude
        if dis <= 200 then
            child.Anchored = false
            child.CanCollide = false
            table.remove(childList,Min,child)
            Min = Min - 1
            wait()
        end
        wait()
    end
    wait()
        end
1
Well, if you removed some of your wait()'s, it would be faster. DeceptiveCaster 3761 — 5y
0
I don't know if you'll see this but, the wait()'s are needed for the script to work properly. Player1_Joined 271 — 5y
0
Not true, arbitrary wait calls don't properly fix anything User#24403 69 — 5y
0
I know they don't fix everything but in this script I need either a waitforchild() somewhere in the script or a normal wait(), I'm not an amazing scripter but I know I atleast need that for the script. Player1_Joined 271 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

remove wait() and add game:GetService("RunService").RenderStepped:wait() try this.

0
This is a serverscript not a localscript, sorry should've said that in the description. Player1_Joined 271 — 5y
0
then try game:GetService("RunService").HeartBeat:Connect(function() iBeatuEZ 27 — 5y
Ad

Answer this question