local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local LocalPlayer = Players.LocalPlayer local Remote = ReplicatedStorage :WaitForChild("RemoteEvents") :WaitForChild("Combat") :WaitForChild("HitHumanoid") local Levels = {"Low","High"} local MAX_DISTANCE = 20 local MAX_DISTANCE_SQ = MAX_DISTANCE * MAX_DISTANCE local enemies = {} local function characterReady() local character = LocalPlayer.Character if not character then return false end local humanoid = character:FindFirstChildOfClass("Humanoid") local root = character:FindFirstChild("HumanoidRootPart") if not humanoid or not root then return false end if humanoid.Health <= 0 then return false end return true end local function getWeapon(character) for _, v in ipairs(character:GetChildren()) do if v:IsA("Tool") then return v end end end local function getRoot(model) return model:FindFirstChild("HumanoidRootPart") or model:FindFirstChild("UpperTorso") or model:FindFirstChild("Torso") or model.PrimaryPart end local function trackModel(model) if Players:GetPlayerFromCharacter(model) then return end task.spawn(function() local humanoid = model:FindFirstChildOfClass("Humanoid") or model:WaitForChild("Humanoid",2) local root = getRoot(model) if not root then root = model:WaitForChild("HumanoidRootPart",2) end if humanoid and root then enemies[model] = { humanoid = humanoid, root = root } humanoid.HealthChanged:Connect(function(h) if h <= 0 then enemies[model] = nil end end) model.AncestryChanged:Connect(function(_, parent) if not parent then enemies[model] = nil end end) end end) end local function scan(container) for _, v in ipairs(container:GetDescendants()) do if v:IsA("Model") then trackModel(v) end end container.DescendantAdded:Connect(function(obj) if obj:IsA("Model") then trackModel(obj) end end) end scan(workspace) while true do task.wait(0.15) if not characterReady() then continue end if next(enemies) == nil then continue end local Character = LocalPlayer.Character local Root = Character.HumanoidRootPart local Weapon = getWeapon(Character) if not Weapon then continue end for model,data in pairs(enemies) do local humanoid = data.humanoid local enemyRoot = data.root if not humanoid or humanoid.Health <= 0 or not enemyRoot then enemies[model] = nil continue end local diff = enemyRoot.Position - Root.Position if diff:Dot(diff) <= MAX_DISTANCE_SQ then Remote:FireServer( Weapon, humanoid, Levels[math.random(1,2)] ) end end end