getgenv().kill = true local GunRemote = game:GetService("ReplicatedStorage").Remotes.GunRemote local Players = game:GetService("Players") local LocalPlayer = Players.LocalPlayer local function getCurrentGun() local char = LocalPlayer.Character if not char then return nil end for _, tool in pairs(char:GetChildren()) do if tool:IsA("Tool") and tool:FindFirstChild("Handle") then return tool end end return nil end local function reload() local gun = getCurrentGun() if gun then GunRemote:FireServer(2, gun) end end local function isAlive(character) if not character then return false end local humanoid = character:FindFirstChildOfClass("Humanoid") return humanoid and humanoid.Health > 0 end local function isBot(character) if character:GetAttribute("AI") == true then return true end end local function getCurrentAmmo() local gui = LocalPlayer.PlayerGui:FindFirstChild("GunGui") if gui then local ammoFrame = gui:FindFirstChild("AmmoFrame") if ammoFrame then local ammoText = ammoFrame:FindFirstChild("AmmoText") if ammoText then local ammo = ammoText:FindFirstChild("Ammo") if ammo then return tonumber(ammo.Text) end end end end return nil end local function requestLoadSelfAsync() local args = {false} game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("RequestLoadSelfAsyncE"):FireServer(unpack(args)) end local function getAllTargets() local targets = {} local myChar = LocalPlayer.Character if not myChar then return targets end local myRoot = myChar:FindFirstChild("HumanoidRootPart") if not myRoot then return targets end local myPos = myRoot.Position for _, player in pairs(Players:GetPlayers()) do if player ~= LocalPlayer then local char = player.Character if char and isAlive(char) then local root = char:FindFirstChild("HumanoidRootPart") if root then table.insert(targets, { character = char, position = root.Position, distance = (myPos - root.Position).Magnitude }) end end end end local characters = workspace:FindFirstChild("Characters") if characters then for _, char in pairs(characters:GetChildren()) do if char ~= myChar and isBot(char) and isAlive(char) then local root = char:FindFirstChild("HumanoidRootPart") if root then table.insert(targets, { character = char, position = root.Position, distance = (myPos - root.Position).Magnitude }) end end end end table.sort(targets, function(a, b) return a.distance < b.distance end) return targets end local function killTarget(targetChar) local gun = getCurrentGun() if not gun then return end local myChar = LocalPlayer.Character if not myChar then return end local myRoot = myChar:FindFirstChild("HumanoidRootPart") if not myRoot then return end local head = targetChar:FindFirstChild("Head") local root = targetChar:FindFirstChild("HumanoidRootPart") if head and root then local headPos = head.Position local myPos = myRoot.Position local direction = (headPos - myPos).Unit local currentAmmo = getCurrentAmmo() if currentAmmo == 0 then requestLoadSelfAsync() end GunRemote:FireServer(1, gun, headPos, direction, root) reload() end end task.spawn(function() while getgenv().kill and task.wait() do local targets = getAllTargets() if #targets > 0 then local nearest = targets[1] if nearest and isAlive(nearest.character) then killTarget(nearest.character) end end end end)