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

How would I make this script use less rate/activity?

Asked by 1 year ago

I made a script for moving multiple models but it messes up when a big amount (70-100) of people get into it. How would I optimize this?

    for i,v in pairs (Map:WaitForChild("Enemies"):GetChildren()) do
        EnemySteppers[v] = {
            Configure = v.Configure,
            prevNode = Map.Spawners.EnemySpawner.CFrame.Position,
            CurrNode = v.Configure.CurrNode.Value,
            Speed = v.Configure.Speed,
            step = 0,
        }
    end    

    coroutine.resume(coroutine.create(function()
        while true do
            for i,v in pairs (EnemySteppers) do
                if v and v.Configure then
                    local Enemy = v
                    local EnemyConfigure = v.Configure
                    local prevNode = v.prevNode
                    local CurrNode = v.CurrNode
                    local Speed = v.Speed.Value
                    if CurrNode ~= 0 and v.prevNode ~= Vector3.new(0,0,0) then
                        if thisPath.Path[CurrNode] ~= nil and i.Parent == Map:WaitForChild("Enemies") and i:WaitForChild("HumanoidRootPart")  then

                            local steps = 50/Speed * ((prevNode - thisPath.Path[CurrNode].Position).magnitude / 1)
                            local step = math.min(v.step + (1/steps),1)
                            if step >= 1 and thisPath.Path[CurrNode+1] then
                                i:SetPrimaryPartCFrame(CFrame.new(prevNode:lerp(thisPath.Path[CurrNode].Position, step), thisPath.Path[CurrNode+1].Position)* CFrame.new(0,.6,0))
                            else
                                i:SetPrimaryPartCFrame(CFrame.new(prevNode:lerp(thisPath.Path[CurrNode].Position, step), thisPath.Path[CurrNode].Position)* CFrame.new(0,.6,0))
                            end
                            v.step=step
                            if v.step >= 1 then 
                                if thisPath.Path[CurrNode+1] ~= nil then
                                    v.prevNode = thisPath.Path[CurrNode].Position
                                    v.CurrNode = v.CurrNode + 1
                                    v.step = 0
                                else
                                    EnemySteppers[i] = nil
                                    Walker.Damage(i,"Tower")
                                    wait(0)
                                    i:Destroy()
                                end
                            end
                        else
                            Walker.Damage(i,"Tower")
                        end
                    else
                        Walker.Damage(i,"Tower")
                    end
                end
            end
            game:GetService("RunService").Stepped:Wait()
        end
    end))
0
ur best bet would be to limit the amount to a lower number ZeroToH3ro 82 — 1y

Answer this question