#optimize aim assist script

1 messages · Page 1 of 1 (latest)

ornate valley
#

How do i optimize this?

the function

local oppositeTeam = if character.Parent == workspace.RedTeam then workspace.BlueTeam else workspace.RedTeam

local closestEnemy
local highestDot = 0

for _, enemy in oppositeTeam:GetChildren() do
    local enemyHumanoid = enemy:FindFirstChild("Humanoid")
    if not enemyHumanoid or enemyHumanoid.Health <= 0 then
        continue
    end
    local enemyPos = enemy:GetPivot().Position
    local lookVector = camera.CFrame.LookVector
    local dir = vector.normalize(enemyPos - camera.CFrame.Position)
    local dot = vector.dot(dir, lookVector)

    if dot > 0.9999 and dot > highestDot then
        closestEnemy = enemy
        highestDot = dot
    end
end

if not closestEnemy then
    return
end

local enemyPos = closestEnemy:GetPivot().Position

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = { character }

local raycast =
    workspace:Raycast(camera.CFrame.Position, (enemyPos - camera.CFrame.Position).Unit * 300, raycastParams)

if raycast and raycast.Instance and not raycast.Instance:IsDescendantOf(closestEnemy) then
    return
end

camera.CFrame = CFrame.lookAt(camera.CFrame.Position, enemyPos)

Code that runs the function

UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType ~= Enum.UserInputType.MouseMovement then
        return
    end

    GunSystem.AimAssist()
end)
boreal dawn
#

Findfirstchild is slow

ornate valley
harsh rootBOT
#

studio** You are now Level 1! **studio

boreal dawn
ornate valley
#

if not enemyHumanoid or enemyHumanoid.Health <= 0 then
continue
end

i need this

boreal dawn