asdas asdasda

18 views
Fallen Survival🏹 3 days ago
asdas asdasda
bread
bread 0 followers

Description

asda
Script
-- AimLock Script - Geoptimaliseerd voor VS Code
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local localPlayer = Players.LocalPlayer
local camera = Workspace.CurrentCamera

-- ==================== INSTELLINGEN ====================
local AIM_LOCK_MAX_DISTANCE = 300
local AIM_SMOOTHNESS = 0.23
local AIM_FOV = 40
local HIGHLIGHT_ENEMIES_RED = true

-- ==================== VARIABELEN ====================
local isRightMouseDown = false
local currentTarget = nil
local lastTargetSearch = 0

-- ==================== HIGHLIGHTS ====================
local function createHighlight(character, player)
    if not character or not player then return end
    
    local existing = character:FindFirstChild("AimHighlight")
    if existing then existing:Destroy() end

    local highlight = Instance.new("Highlight")
    highlight.Name = "AimHighlight"
    highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    highlight.FillTransparency = 0.65
    highlight.OutlineTransparency = 0.1
    highlight.Parent = character

    if HIGHLIGHT_ENEMIES_RED and player.Team ~= localPlayer.Team then
        highlight.FillColor = Color3.fromRGB(255, 65, 65)
        highlight.OutlineColor = Color3.fromRGB(255, 140, 140)
    else
        highlight.FillColor = player.TeamColor.Color
        highlight.OutlineColor = player.TeamColor.Color
    end
end

local function applyHighlights(player)
    if player == localPlayer then return end

    local function onCharacterAdded(char)
        createHighlight(char, player)
    end

    if player.Character then
        onCharacterAdded(player.Character)
    end
    player.CharacterAdded:Connect(onCharacterAdded)
end

for _, plr in ipairs(Players:GetPlayers()) do
    applyHighlights(plr)
end
Players.PlayerAdded:Connect(applyHighlights)

-- ==================== TARGET FINDER ====================
local function isTargetValid(target)
    if not target or not target.Character then return false end
    local hum = target.Character:FindFirstChild("Humanoid")
    local head = target.Character:FindFirstChild("Head")
    return hum and hum.Health > 0 and head
end

local function getClosestEnemyToCrosshair()
    local now = tick()
    if now - lastTargetSearch < 0.08 and isTargetValid(currentTarget) then
        return currentTarget
    end
    lastTargetSearch = now

    local closest = nil
    local bestDist = math.huge
    local center = camera.ViewportSize / 2
    local myRoot = localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart")
    if not myRoot then return nil end

    for _, player in ipairs(Players:GetPlayers()) do
        if player ~= localPlayer and player.Team ~= localPlayer.Team then
            local char = player.Character
            if char and char:FindFirstChild("Head") then
                local hum = char:FindFirstChild("Humanoid")
                if hum and hum.Health > 0 then
                    local screenPos, onScreen = camera:WorldToViewportPoint(char.Head.Position)
                    if onScreen then
                        local dist2D = (Vector2.new(screenPos.X, screenPos.Y) - center).Magnitude
                        local dist3D = (char.Head.Position - myRoot.Position).Magnitude

                        if dist3D <= AIM_LOCK_MAX_DISTANCE and dist2D < bestDist and dist2D <= AIM_FOV then
                            bestDist = dist2D
                            closest = player
                        end
                    end
                end
            end
        end
    end
    return closest
end

-- ==================== INPUT ====================
UserInputService.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        isRightMouseDown = true
        currentTarget = nil
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        isRightMouseDown = false
        currentTarget = nil
    end
end)

-- ==================== MAIN LOOP ====================
RunService.RenderStepped:Connect(function(dt)
    if not isRightMouseDown then 
        currentTarget = nil
        return 
    end

    if not isTargetValid(currentTarget) then
        currentTarget = getClosestEnemyToCrosshair()
    end

    if currentTarget and currentTarget.Character and currentTarget.Character:FindFirstChild("Head") then
        local targetPos = currentTarget.Character.Head.Position
        local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetPos)
        
        camera.CFrame = camera.CFrame:Lerp(targetCFrame, 1 - math.pow(1 - AIM_SMOOTHNESS, dt * 60))
    end
end)

print("✅ Aimlock script geladen vanuit VS Code!")

Fallen Survival🏹

Explore more scripts for this game

0 Comments

Log in to comment
No comments yet. Be the first!

View Script

-- AimLock Script - Geoptimaliseerd voor VS Code
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local localPlayer = Players.LocalPlayer
local camera = Workspace.CurrentCamera

-- ==================== INSTELLINGEN ====================
local AIM_LOCK_MAX_DISTANCE = 300
local AIM_SMOOTHNESS = 0.23
local AIM_FOV = 40
local HIGHLIGHT_ENEMIES_RED = true

-- ==================== VARIABELEN ====================
local isRightMouseDown = false
local currentTarget = nil
local lastTargetSearch = 0

-- ==================== HIGHLIGHTS ====================
local function createHighlight(character, player)
    if not character or not player then return end
    
    local existing = character:FindFirstChild("AimHighlight")
    if existing then existing:Destroy() end

    local highlight = Instance.new("Highlight")
    highlight.Name = "AimHighlight"
    highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    highlight.FillTransparency = 0.65
    highlight.OutlineTransparency = 0.1
    highlight.Parent = character

    if HIGHLIGHT_ENEMIES_RED and player.Team ~= localPlayer.Team then
        highlight.FillColor = Color3.fromRGB(255, 65, 65)
        highlight.OutlineColor = Color3.fromRGB(255, 140, 140)
    else
        highlight.FillColor = player.TeamColor.Color
        highlight.OutlineColor = player.TeamColor.Color
    end
end

local function applyHighlights(player)
    if player == localPlayer then return end

    local function onCharacterAdded(char)
        createHighlight(char, player)
    end

    if player.Character then
        onCharacterAdded(player.Character)
    end
    player.CharacterAdded:Connect(onCharacterAdded)
end

for _, plr in ipairs(Players:GetPlayers()) do
    applyHighlights(plr)
end
Players.PlayerAdded:Connect(applyHighlights)

-- ==================== TARGET FINDER ====================
local function isTargetValid(target)
    if not target or not target.Character then return false end
    local hum = target.Character:FindFirstChild("Humanoid")
    local head = target.Character:FindFirstChild("Head")
    return hum and hum.Health > 0 and head
end

local function getClosestEnemyToCrosshair()
    local now = tick()
    if now - lastTargetSearch < 0.08 and isTargetValid(currentTarget) then
        return currentTarget
    end
    lastTargetSearch = now

    local closest = nil
    local bestDist = math.huge
    local center = camera.ViewportSize / 2
    local myRoot = localPlayer.Character and localPlayer.Character:FindFirstChild("HumanoidRootPart")
    if not myRoot then return nil end

    for _, player in ipairs(Players:GetPlayers()) do
        if player ~= localPlayer and player.Team ~= localPlayer.Team then
            local char = player.Character
            if char and char:FindFirstChild("Head") then
                local hum = char:FindFirstChild("Humanoid")
                if hum and hum.Health > 0 then
                    local screenPos, onScreen = camera:WorldToViewportPoint(char.Head.Position)
                    if onScreen then
                        local dist2D = (Vector2.new(screenPos.X, screenPos.Y) - center).Magnitude
                        local dist3D = (char.Head.Position - myRoot.Position).Magnitude

                        if dist3D <= AIM_LOCK_MAX_DISTANCE and dist2D < bestDist and dist2D <= AIM_FOV then
                            bestDist = dist2D
                            closest = player
                        end
                    end
                end
            end
        end
    end
    return closest
end

-- ==================== INPUT ====================
UserInputService.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        isRightMouseDown = true
        currentTarget = nil
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton2 then
        isRightMouseDown = false
        currentTarget = nil
    end
end)

-- ==================== MAIN LOOP ====================
RunService.RenderStepped:Connect(function(dt)
    if not isRightMouseDown then 
        currentTarget = nil
        return 
    end

    if not isTargetValid(currentTarget) then
        currentTarget = getClosestEnemyToCrosshair()
    end

    if currentTarget and currentTarget.Character and currentTarget.Character:FindFirstChild("Head") then
        local targetPos = currentTarget.Character.Head.Position
        local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetPos)
        
        camera.CFrame = camera.CFrame:Lerp(targetCFrame, 1 - math.pow(1 - AIM_SMOOTHNESS, dt * 60))
    end
end)

print("✅ Aimlock script geladen vanuit VS Code!")