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

Is it possible to optimize this script? [closed]

Asked by 6 years ago

My script starts off with 12% Activity rate according to the Script Performance screen, but it soon drops down to 3%. Then, as I approach a target, to builds up to nearly 7%. Any way I can optimize the script?

local player = game.Players.LocalPlayer

while game.Workspace:FindFirstChild(player.Name) == nil do
    wait(0.1)
end

local cam = workspace.CurrentCamera

for _, i in pairs(workspace.Targets:GetChildren()) do
    if i.Name == "Target" then
        if i.ForAsset.Value == true then
            i.ReleaseSensitivity.Value = 14
        else
            i.ReleaseSensitivity.Value = 7.5
        end

        i.Buffer.Value = 71
        local Buffer = i.Buffer.Value
        local pos = i.Position

        local oof = game:GetService("RunService").Heartbeat:Connect(function()
            if game.Workspace:FindFirstChild(player.Name) ~= nil and player:DistanceFromCharacter(pos) < Buffer + 18 then
                local Distance = player:DistanceFromCharacter(pos)

                if Distance < Buffer and i.Wait.Value == false and cam:WorldToScreenPoint(pos).Z > 0 then
                    if i.Name ~= "HA" then
                        i.Name = "Beepbeep"
                    end

                    if i.Name == "Beepbeep" and workspace.Targets:FindFirstChild("HA") == nil then
                        script.LockOn:Play()
                        i.Name = "HA"
                    end
                else
                    i.Name = "Target"
                end
            end
        end)
    end
end

By the way, there are around 70 parts named "Target", so it keeps up with those 70 targets actively.

So what the script does is check for each part named "Target", and then checks to see if you're 71 studs away from it. If you are, it changes the part's name twice (the first one is part of a queue system thought up by yours truly). Then, once you're out of range, it changes the name back to "Target".

Closed as Not Constructive by 1TheNoobestNoob, zblox164, green271, User#22604, and Amiaa16

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?