Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local Camera = workspace.CurrentCamera
- local LocalPlayer = Players.LocalPlayer
- -- Settings
- local FOVRadius = 200 -- Adjust the radius of the FOV circle
- local ThirdPersonThreshold = 5 -- Adjust this value to determine third-person view threshold
- local FOVCircle = Drawing.new("Circle")
- FOVCircle.Radius = FOVRadius
- FOVCircle.Color = Color3.fromRGB(255, 255, 255)
- FOVCircle.Thickness = 2
- FOVCircle.Transparency = 1
- FOVCircle.Filled = false
- -- Silent Aim
- local function isVisible(target)
- local character = target.Character
- if character and character:FindFirstChild("Head") then
- local ray = Ray.new(Camera.CFrame.Position, (character.Head.Position - Camera.CFrame.Position).unit * 500)
- local hit = workspace:FindPartOnRay(ray, LocalPlayer.Character)
- return hit and hit:IsDescendantOf(character)
- end
- return false
- end
- local function getNearestPlayer()
- local nearestPlayer = nil
- local shortestDistance = FOVRadius
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= LocalPlayer and player.Team ~= LocalPlayer.Team then
- local character = player.Character
- local head = character and character:FindFirstChild("Head")
- if head then
- local headPosition, onScreen = Camera:WorldToViewportPoint(head.Position)
- local mousePosition = UserInputService:GetMouseLocation()
- local distanceFromMouse = (Vector2.new(headPosition.X, headPosition.Y) - mousePosition).Magnitude
- if onScreen and distanceFromMouse < shortestDistance and isVisible(player) then
- nearestPlayer = player
- shortestDistance = distanceFromMouse
- end
- end
- end
- end
- return nearestPlayer
- end
- -- Check if the player is in third-person view
- local function isThirdPerson()
- local character = LocalPlayer.Character
- if character and character:FindFirstChild("Head") then
- local distance = (Camera.CFrame.Position - character.Head.Position).Magnitude
- return distance > ThirdPersonThreshold
- end
- return false
- end
- -- Update FOV Circle Position to be centered around the mouse
- local function updateFOVCircle()
- local mousePosition = UserInputService:GetMouseLocation()
- FOVCircle.Position = mousePosition -- Centers the FOV circle at the current mouse position
- end
- -- Camlock functionality
- local function camlockAtTarget(target)
- if target and target.Character and target.Character:FindFirstChild("Head") then
- -- Lock the camera's CFrame onto the target's head
- Camera.CFrame = CFrame.new(Camera.CFrame.Position, target.Character.Head.Position)
- end
- end
- -- Silent Aim functionality
- local function silentAimAtTarget(target)
- if target and target.Character and target.Character:FindFirstChild("Head") then
- -- Silently aim at the target by adjusting the camera's direction
- Camera.CFrame = CFrame.new(Camera.CFrame.Position, target.Character.Head.Position)
- end
- end
- -- Main loop to handle aiming
- RunService.RenderStepped:Connect(function()
- updateFOVCircle()
- local target = getNearestPlayer()
- if target then
- if isThirdPerson() then
- camlockAtTarget(target) -- Use camlock in third-person
- else
- silentAimAtTarget(target) -- Use silent aim in first-person
- end
- end
- end)
- -- Cleanup on game exit
- game.Players.LocalPlayer.OnTeleport:Connect(function()
- FOVCircle:Remove()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement