
KeylessUniversal

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")
local LocalPlayer = Players.LocalPlayer
local Camera = Workspace.CurrentCamera
-- Configuration State
local Config = {
TargetLock = true, -- Changed to TRUE by default so it works immediately
WallCheck = true,
FOV = 150,
TrackingSpeed = 0.5, -- 0.01 (Very Slow) to 1 (Instant snap)
AimKeybind = Enum.KeyCode.E,
SwitchKeybind = Enum.KeyCode.Q,
UIToggleKeybind = Enum.KeyCode.RightShift
}
-- Runtime State
local isAiming = false
local currentTarget = nil
--========================================================
-- UI CREATION
--========================================================
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "TargetingUI"
ScreenGui.ResetOnSpawn = false
ScreenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")
-- FOV VISUALIZER (Always visible)
local FOVCircle = Instance.new("Frame")
FOVCircle.Name = "FOVCircle"
FOVCircle.AnchorPoint = Vector2.new(0.5, 0.5)
FOVCircle.Position = UDim2.new(0.5, 0, 0.5, 0)
FOVCircle.Size = UDim2.new(0, Config.FOV * 2, 0, Config.FOV * 2)
FOVCircle.BackgroundTransparency = 1
FOVCircle.Parent = ScreenGui
local FOVCorner = Instance.new("UICorner")
FOVCorner.CornerRadius = UDim.new(0.5, 0)
FOVCorner.Parent = FOVCircle
local FOVStroke = Instance.new("UIStroke")
FOVStroke.Color = Color3.fromRGB(255, 50, 50)
FOVStroke.Thickness = 1.5
FOVStroke.Transparency = 0.2
FOVStroke.Parent = FOVCircle
-- Menu Toggle Button (Mobile/PC)
local OpenCloseBtn = Instance.new("TextButton")
OpenCloseBtn.Size = UDim2.new(0, 80, 0, 30)
OpenCloseBtn.Position = UDim2.new(0, 10, 0, 10)
OpenCloseBtn.BackgroundColor3 = Color3.fromRGB(40, 40, 45)
OpenCloseBtn.Text = "Menu"
OpenCloseBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
OpenCloseBtn.Font = Enum.Font.GothamBold
OpenCloseBtn.TextSize = 12
Instance.new("UICorner", OpenCloseBtn).CornerRadius = UDim.new(0, 6)
OpenCloseBtn.Parent = ScreenGui
-- Main Menu Window
local MainFrame = Instance.new("Frame")
MainFrame.Size = UDim2.new(0, 240, 0, 280)
MainFrame.Position = UDim2.new(0.05, 0, 0.2, 0)
MainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 35)
MainFrame.BorderSizePixel = 0
MainFrame.Active = true
MainFrame.Parent = ScreenGui
local UICorner = Instance.new("UICorner")
UICorner.CornerRadius = UDim.new(0, 8)
UICorner.Parent = MainFrame
local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, 0, 0, 35)
Title.BackgroundTransparency = 1
Title.Text = "TARGETING SYSTEM"
Title.TextColor3 = Color3.fromRGB(255, 255, 255)
Title.Font = Enum.Font.GothamBold
Title.TextSize = 14
Title.Parent = MainFrame
local UIListLayout = Instance.new("UIListLayout")
UIListLayout.Parent = MainFrame
UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder
UIListLayout.Padding = UDim.new(0, 8)
UIListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
OpenCloseBtn.MouseButton1Click:Connect(function()
MainFrame.Visible = not MainFrame.Visible
end)
-- Make Menu Draggable
local dragging, dragInput, dragStart, startPos
MainFrame.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = MainFrame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then dragging = false end
end)
end
end)
MainFrame.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then dragInput = input end
end)
UserInputService.InputChanged:Connect(function(input)
if input == dragInput and dragging then
local delta = input.Position - dragStart
MainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end
end)
-- UI Helpers
local function createToggle(name, defaultState, callback)
local Btn = Instance.new("TextButton")
Btn.Size = UDim2.new(0.9, 0, 0, 35)
Btn.BackgroundColor3 = defaultState and Color3.fromRGB(80, 200, 80) or Color3.fromRGB(200, 80, 80)
Btn.Text = name .. ": " .. (defaultState and "ON" or "OFF")
Btn.TextColor3 = Color3.fromRGB(255, 255, 255)
Btn.Font = Enum.Font.GothamSemibold
Btn.TextSize = 13
Instance.new("UICorner", Btn).CornerRadius = UDim.new(0, 6)
Btn.Parent = MainFrame
local state = defaultState
Btn.MouseButton1Click:Connect(function()
state = not state
Btn.BackgroundColor3 = state and Color3.fromRGB(80, 200, 80) or Color3.fromRGB(200, 80, 80)
Btn.Text = name .. ": " .. (state and "ON" or "OFF")
callback(state)
end)
end
local function createInput(name, defaultVal, callback)
local Frame = Instance.new("Frame")
Frame.Size = UDim2.new(0.9, 0, 0, 35)
Frame.BackgroundTransparency = 1
Frame.Parent = MainFrame
local Label = Instance.new("TextLabel")
Label.Size = UDim2.new(0.6, 0, 1, 0)
Label.BackgroundTransparency = 1
Label.Text = name
Label.TextColor3 = Color3.fromRGB(200, 200, 200)
Label.Font = Enum.Font.Gotham
Label.TextSize = 13
Label.TextXAlignment = Enum.TextXAlignment.Left
Label.Parent = Frame
local TextBox = Instance.new("TextBox")
TextBox.Size = UDim2.new(0.35, 0, 1, 0)
TextBox.Position = UDim2.new(0.65, 0, 0, 0)
TextBox.BackgroundColor3 = Color3.fromRGB(50, 50, 55)
TextBox.TextColor3 = Color3.fromRGB(255, 255, 255)
TextBox.Text = tostring(defaultVal)
TextBox.Font = Enum.Font.Gotham
TextBox.TextSize = 13
Instance.new("UICorner", TextBox).CornerRadius = UDim.new(0, 6)
TextBox.Parent = Frame
TextBox.FocusLost:Connect(function()
callback(TextBox.Text)
end)
end
local TitlePadding = Instance.new("Frame")
TitlePadding.Size = UDim2.new(1,0,0,2)
TitlePadding.BackgroundTransparency = 1
TitlePadding.Parent = MainFrame
createToggle("Target Lock", Config.TargetLock, function(val) Config.TargetLock = val end)
createToggle("Wall Check", Config.WallCheck, function(val) Config.WallCheck = val end)
createInput("FOV Radius", Config.FOV, function(val)
local newFOV = tonumber(val) or Config.FOV
Config.FOV = newFOV
FOVCircle.Size = UDim2.new(0, newFOV * 2, 0, newFOV * 2) -- Dynamically updates UI FOV
end)
createInput("Aim Speed", Config.TrackingSpeed, function(val)
Config.TrackingSpeed = math.clamp(tonumber(val) or Config.TrackingSpeed, 0.01, 1)
end)
--========================================================
-- ADVANCED LOGIC & MATH
--========================================================
-- Recursive Piercing Raycast (Ignores invisible/non-solid barriers)
local function getPiercingRaycast(origin, direction, targetChar, ignoreList, depth)
if depth > 5 then return false end -- Safety limit to prevent lag
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = ignoreList
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.IgnoreWater = true
local result = Workspace:Raycast(origin, direction, rayParams)
if result then
if result.Instance:IsDescendantOf(targetChar) then
return true -- Successfully hit the target
end
-- If it hits an invisible part, non-collidable part, or baseplate, ignore it and keep raycasting
if result.Instance.Transparency >= 0.5 or not result.Instance.CanCollide or result.Instance.Name == "HumanoidRootPart" then
table.insert(ignoreList, result.Instance)
return getPiercingRaycast(origin, direction, targetChar, ignoreList, depth + 1)
end
return false -- We hit a solid, visible wall
end
return true -- We hit absolutely nothing, path is completely clear
end
local function isVisible(targetChar)
if not Config.WallCheck then return true end
-- Prioritize the Head because feet/torso often clip through floors, breaking the check
local targetPart = targetChar:FindFirstChild("Head") or targetChar:FindFirstChild("HumanoidRootPart")
if not targetPart then return false end
local origin = Camera.CFrame.Position
local direction = targetPart.Position - origin
local ignoreList = {}
if LocalPlayer.Character then
table.insert(ignoreList, LocalPlayer.Character)
end
return getPiercingRaycast(origin, direction, targetChar, ignoreList, 0)
end
local function getClosestTarget(excludeTarget)
local closestPlayer = nil
local shortestDistance = Config.FOV
local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
for _, player in pairs(Players:GetPlayers()) do
if player ~= LocalPlayer and player.Character then
local targetPart = player.Character:FindFirstChild("Head") or player.Character:FindFirstChild("HumanoidRootPart")
local humanoid = player.Character:FindFirstChild("Humanoid")
if targetPart and humanoid and humanoid.Health > 0 and player.Character ~= excludeTarget then
local screenPoint, onScreen = Camera:WorldToViewportPoint(targetPart.Position)
if onScreen then
local distance = (Vector2.new(screenPoint.X, screenPoint.Y) - screenCenter).Magnitude
if distance <= shortestDistance then
if isVisible(player.Character) then
shortestDistance = distance
closestPlayer = player.Character
end
end
end
end
end
end
return closestPlayer
end
--========================================================
-- CONTROLS
--========================================================
ContextActionService:BindAction("AimLockAction", function(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
isAiming = not isAiming
if isAiming then
FOVStroke.Color = Color3.fromRGB(50, 255, 50) -- Crosshair Turns Green
else
currentTarget = nil
FOVStroke.Color = Color3.fromRGB(255, 50, 50) -- Crosshair Turns Red
end
end
end, true, Config.AimKeybind)
ContextActionService:SetTitle("AimLockAction", "Aim")
ContextActionService:SetPosition("AimLockAction", UDim2.new(0.7, 0, 0.5, 0))
ContextActionService:BindAction("SwitchTargetAction", function(actionName, inputState)
if inputState == Enum.UserInputState.Begin and isAiming then
local newTarget = getClosestTarget(currentTarget)
if newTarget then currentTarget = newTarget end
end
end, true, Config.SwitchKeybind)
ContextActionService:SetTitle("SwitchTargetAction", "Switch")
ContextActionService:SetPosition("SwitchTargetAction", UDim2.new(0.7, 0, 0.35, 0))
-- Keyboard shortcut to open/close menu
ContextActionService:BindAction("ToggleUIAction", function(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
MainFrame.Visible = not MainFrame.Visible
end
end, false, Config.UIToggleKeybind)
--========================================================
-- CONTINUOUS CAMERA AIM & AUTO-RETARGET
--========================================================
RunService:BindToRenderStep("AimLockLoop", Enum.RenderPriority.Camera.Value + 1, function()
if Config.TargetLock and isAiming then
-- 1. Validate Current Target
if currentTarget then
local targetPart = currentTarget:FindFirstChild("Head") or currentTarget:FindFirstChild("HumanoidRootPart")
local humanoid = currentTarget:FindFirstChild("Humanoid")
if not targetPart or not humanoid or humanoid.Health <= 0 then
currentTarget = nil -- Target died or despawned
elseif Config.WallCheck and not isVisible(currentTarget) then
currentTarget = nil -- Target went behind a solid wall
else
-- Check if target escaped the FOV radius
local screenPoint, onScreen = Camera:WorldToViewportPoint(targetPart.Position)
local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
local distance = (Vector2.new(screenPoint.X, screenPoint.Y) - screenCenter).Magnitude
if not onScreen or distance > Config.FOV then
currentTarget = nil
end
end
end
-- 2. Auto-Acquire New Target (if we lost the old one)
if not currentTarget then
currentTarget = getClosestTarget()
end
-- 3. Snap Camera to Target
if currentTarget then
local targetPart = currentTarget:FindFirstChild("Head") or currentTarget:FindFirstChild("HumanoidRootPart")
local targetCFrame = CFrame.lookAt(Camera.CFrame.Position, targetPart.Position)
Camera.CFrame = Camera.CFrame:Lerp(targetCFrame, Config.TrackingSpeed)
end
end
end)No comments yet for this script.



