local Players = game:GetService("Players") local LocalPlayer = Players.LocalPlayer local PlayerScripts = LocalPlayer:WaitForChild("PlayerScripts") local Controllers = PlayerScripts:WaitForChild("Controllers") local GunClientModule = require(Controllers:WaitForChild("GunClient")) local ZombiesFolder = workspace:WaitForChild("Zombies_Local", 15) local function isValidZombie(model) if not model or not model:IsA("Model") then return false end local animController = model:FindFirstChild("AnimationController") if animController and animController:IsA("AnimationController") then return true end return false end local function getHumanoidRootPart(model) if not model:IsA("Model") then return nil end return model:FindFirstChild("HumanoidRootPart") or model.PrimaryPart end local function getClosestZombieRootPart(origin) local closestDistSq = math.huge local closestPart = nil for _, child in ipairs(ZombiesFolder:GetChildren()) do if isValidZombie(child) then local rootPart = getHumanoidRootPart(child) if rootPart and rootPart:IsA("BasePart") then local delta = rootPart.Position - origin local distSq = delta.X*delta.X + delta.Y*delta.Y + delta.Z*delta.Z if distSq < closestDistSq then closestDistSq = distSq closestPart = rootPart end end end end return closestPart end local cachedTarget = nil local lastUpdateTime = 0 local UPDATE_INTERVAL = 0.1 local function updateClosestTarget(origin) local now = tick() if now - lastUpdateTime > UPDATE_INTERVAL then lastUpdateTime = now cachedTarget = getClosestZombieRootPart(origin) end return cachedTarget end local MAX_PITCH = math.rad(60) local function clampDirection(direction) local flatDir = Vector3.new(direction.X, 0, direction.Z) if flatDir.Magnitude < 0.001 then return direction end flatDir = flatDir.Unit local verticalAngle = math.asin(math.clamp(direction.Y, -1, 1)) if math.abs(verticalAngle) > MAX_PITCH then local newY = math.sin(MAX_PITCH * math.sign(verticalAngle)) local newFlat = math.cos(MAX_PITCH) return (flatDir * newFlat + Vector3.new(0, newY, 0)).Unit end return direction end local originalGetAimDirection = GunClientModule.GetAimDirection GunClientModule.GetAimDirection = function(self) local fireOrigin = self:GetFireOrigin() if not fireOrigin then if self.HumanoidRootPart then fireOrigin = self.HumanoidRootPart.Position else return originalGetAimDirection(self) end end local targetRoot = updateClosestTarget(fireOrigin) if targetRoot then local direction = (targetRoot.Position - fireOrigin).Unit direction = clampDirection(direction) if direction.Magnitude > 0.001 then return direction end end return originalGetAimDirection(self) end ZombiesFolder.ChildAdded:Connect(function() cachedTarget = nil lastUpdateTime = 0 end) ZombiesFolder.ChildRemoved:Connect(function() cachedTarget = nil lastUpdateTime = 0 end)