local plrs = game:GetService("Players")
local runSvc = game:GetService("RunService")
local inputSvc = game:GetService("UserInputService")
local repStorage = game:GetService("ReplicatedStorage")
local plr = plrs.LocalPlayer
local cam = workspace.CurrentCamera
local enabled = true
local targetHead = true
local visCheck = false
local fov = 200
local toggleKey = Enum.KeyCode.X
local function getNearestEnemy()
local char = plr.Character
if not char or not char:FindFirstChild("HumanoidRootPart") then
return nil
end
local mousePos = inputSvc:GetMouseLocation()
local currentCam = workspace.CurrentCamera
if not currentCam then return nil end
local bestPos = nil
local bestDist = math.huge
for _, otherPlr in ipairs(plrs:GetPlayers()) do
if otherPlr ~= plr then
local enemyChar = otherPlr.Character
if enemyChar then
local hum = enemyChar:FindFirstChildOfClass("Humanoid")
if hum and hum.Health > 0 then
local part = targetHead and enemyChar:FindFirstChild("Head") or enemyChar:FindFirstChild("HumanoidRootPart")
if part then
local pos = part.Position
local screenPos, onScreen = currentCam:WorldToScreenPoint(pos)
if onScreen and screenPos.Z > 0 then
local dist = (Vector2.new(screenPos.X, screenPos.Y) - mousePos).Magnitude
if fov == 0 or dist <= fov then
if visCheck then
local root = char.HumanoidRootPart
local origin = root.Position
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {char, cam}
local ray = workspace:Raycast(origin, (pos - origin).Unit * 1000, rayParams)
if not ray or ray.Instance:IsDescendantOf(enemyChar) then
if dist < bestDist then
bestDist = dist
bestPos = pos
end
end
else
if dist < bestDist then
bestDist = dist
bestPos = pos
end
end
end
end
end
end
end
end
end
return bestPos
end
local hooked = setmetatable({}, {__mode = "k"})
local function hookCrosshair(handler)
if not handler then return end
if hooked[handler] then return end
if not handler._oldGetPos then
handler._oldGetPos = handler.GetPosition
end
handler.GetPosition = function(self, ...)
if enabled then
local pos = getNearestEnemy()
if pos then
return pos, nil
end
end
return handler._oldGetPos(self, ...)
end
hooked[handler] = true
end
local function hookAllGuns()
local gunKit = require(repStorage.Modules.GunKit.GunLocal)
if gunKit and gunKit.Registry then
for _, gun in ipairs(gunKit.Registry) do
if gun.CrosshairHandler then
hookCrosshair(gun.CrosshairHandler)
end
end
end
end
runSvc.RenderStepped:Connect(function()
hookAllGuns()
end)
local function onCharAdded()
task.wait(0.5)
hookAllGuns()
end
plr.CharacterAdded:Connect(onCharAdded)
if plr.Character then
onCharAdded()
end
inputSvc.InputBegan:Connect(function(input, gp)
if gp then return end
if input.KeyCode == toggleKey then
enabled = not enabled
print("silent aim: " .. (enabled and "on" or "off"))
end
end)
Comments
No comments yet
Be the first to share your thoughts!