Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Target Lock Script for Roblox
- -- Created by Claude
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local Mouse = LocalPlayer:GetMouse()
- -- Target Lock Configuration
- local Config = {
- Enabled = false,
- Key = Enum.KeyCode.Q,
- FOV = {
- Size = 120,
- Transparency = 0.7,
- Thickness = 1,
- Filled = false,
- Color = Color3.fromRGB(255, 255, 255)
- },
- HitPart = "HumanoidRootPart", -- Default part to target
- AirShotHitPart = "LowerTorso", -- Part to target when player is in air
- Prediction = {
- X = 0.06,
- Y = 0.3
- },
- JumpOffset = 0.02, -- Vertical offset when target jumps
- Hitbox = {
- Size = 25,
- Transparency = 0.07,
- Color = Color3.fromRGB(255, 0, 0)
- }
- }
- -- Variables
- local Target = nil
- local FOVCircle = Drawing.new("Circle")
- local HitboxPart = nil
- -- Initialize FOV Circle
- FOVCircle.Visible = false
- FOVCircle.Radius = Config.FOV.Size
- FOVCircle.Transparency = Config.FOV.Transparency
- FOVCircle.Thickness = Config.FOV.Thickness
- FOVCircle.Filled = Config.FOV.Filled
- FOVCircle.Color = Config.FOV.Color
- FOVCircle.Position = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- -- Function to check if a player is valid for targeting
- local function IsValidTarget(player)
- if player == LocalPlayer then return false end
- if not player.Character then return false end
- if not player.Character:FindFirstChild("Humanoid") then return false end
- if player.Character.Humanoid.Health <= 0 then return false end
- -- Check if player is within FOV
- local screenPos, onScreen = Camera:WorldToScreenPoint(player.Character.HumanoidRootPart.Position)
- if not onScreen then return false end
- local distance = (Vector2.new(screenPos.X, screenPos.Y) - FOVCircle.Position).Magnitude
- if distance > FOVCircle.Radius then return false end
- -- Check for line of sight
- local rayParams = RaycastParams.new()
- rayParams.FilterDescendantsInstances = {LocalPlayer.Character}
- rayParams.FilterType = Enum.RaycastFilterType.Blacklist
- local direction = (player.Character.HumanoidRootPart.Position - Camera.CFrame.Position).Unit
- local rayResult = workspace:Raycast(Camera.CFrame.Position, direction * 1000, rayParams)
- if rayResult and rayResult.Instance and rayResult.Instance:IsDescendantOf(player.Character) then
- return true
- end
- return false
- end
- -- Function to get the closest player within FOV
- local function GetClosestPlayerInFOV()
- local closestPlayer = nil
- local shortestDistance = math.huge
- for _, player in pairs(Players:GetPlayers()) do
- if IsValidTarget(player) then
- local screenPos = Camera:WorldToScreenPoint(player.Character.HumanoidRootPart.Position)
- local distance = (Vector2.new(screenPos.X, screenPos.Y) - FOVCircle.Position).Magnitude
- if distance < shortestDistance then
- closestPlayer = player
- shortestDistance = distance
- end
- end
- end
- return closestPlayer
- end
- -- Function to create or update the hitbox
- local function UpdateHitbox()
- if not HitboxPart then
- HitboxPart = Instance.new("Part")
- HitboxPart.Name = "TargetHitbox"
- HitboxPart.Anchored = true
- HitboxPart.CanCollide = false
- HitboxPart.Material = Enum.Material.Neon
- HitboxPart.Shape = Enum.PartType.Ball
- HitboxPart.Parent = workspace
- end
- if Target and Target.Character then
- HitboxPart.Size = Vector3.new(Config.Hitbox.Size, Config.Hitbox.Size, Config.Hitbox.Size)
- HitboxPart.Transparency = Config.Hitbox.Transparency
- HitboxPart.Color = Config.Hitbox.Color
- HitboxPart.Visible = true
- else
- HitboxPart.Visible = false
- end
- end
- -- Function to get the target part based on if the player is in air
- local function GetTargetPart()
- if not Target or not Target.Character then return nil end
- local humanoid = Target.Character:FindFirstChild("Humanoid")
- if humanoid and humanoid:GetState() == Enum.HumanoidStateType.Jumping or
- humanoid:GetState() == Enum.HumanoidStateType.Freefall then
- return Target.Character:FindFirstChild(Config.AirShotHitPart)
- end
- return Target.Character:FindFirstChild(Config.HitPart)
- end
- -- Toggle target lock
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.KeyCode == Config.Key then
- Config.Enabled = not Config.Enabled
- FOVCircle.Visible = Config.Enabled
- if Config.Enabled then
- Target = GetClosestPlayerInFOV()
- UpdateHitbox()
- else
- Target = nil
- if HitboxPart then
- HitboxPart.Visible = false
- end
- end
- end
- end)
- -- Main target lock loop
- RunService.RenderStepped:Connect(function()
- -- Update FOV circle position
- FOVCircle.Position = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- if Config.Enabled and Target then
- -- Check if target is still valid
- if not IsValidTarget(Target) then
- Target = GetClosestPlayerInFOV()
- end
- if Target then
- -- Get target part
- local targetPart = GetTargetPart()
- if not targetPart then return end
- -- Apply prediction and jump offset
- local targetPosition = targetPart.Position
- local velocity = targetPart.Velocity
- -- Apply prediction
- local predictedPosition = targetPosition + (velocity * Vector3.new(Config.Prediction.X, 0, Config.Prediction.Y))
- -- Apply jump offset if needed
- local humanoid = Target.Character:FindFirstChild("Humanoid")
- if humanoid and (humanoid:GetState() == Enum.HumanoidStateType.Jumping or
- humanoid:GetState() == Enum.HumanoidStateType.Freefall) then
- predictedPosition = predictedPosition + Vector3.new(0, Config.JumpOffset, 0)
- end
- -- Update camera to look at target
- Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, predictedPosition)
- -- Update hitbox position
- if HitboxPart then
- HitboxPart.Position = targetPosition
- end
- end
- end
- end)
- -- GUI elements for settings (optional)
- local function CreateSettingsGUI()
- -- Create basic settings GUI to adjust all parameters
- -- This is left as an extension point
- end
- -- Update hitbox when target changes
- RunService.Heartbeat:Connect(function()
- if Config.Enabled and Target then
- UpdateHitbox()
- end
- end)
- -- Cleanup on script unload
- game:GetService("CoreGui").ChildRemoved:Connect(function(child)
- if child.Name == script.Name then
- FOVCircle:Remove()
- if HitboxPart then
- HitboxPart:Destroy()
- end
- end
- end)
- print("Target Lock script loaded! Press Q to toggle.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement