local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local Workspace = game:GetService("Workspace") local player = Players.LocalPlayer local remotes = ReplicatedStorage:WaitForChild("Remotes") local attackRemote = remotes:WaitForChild("Attack") local swingRemote = remotes:FindFirstChild("Swing") local lastAttack = 0 local attackCount = 0 local cooldown = 0.625 local function getEyePosition(character) if not character then return nil end local root = character:FindFirstChild("HumanoidRootPart") if not root then return nil end return root.Position / 3 + Vector3.new(0, 0.72, 0) end RunService.Heartbeat:Connect(function() if tick() - lastAttack < cooldown then return end local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") if not humanoid or humanoid.Health <= 0 then return end local eyePosition = getEyePosition(character) if not eyePosition then return end local closestTarget = nil local closestDistance = 4 for _, otherPlayer in ipairs(Players:GetPlayers()) do if otherPlayer ~= player then local otherCharacter = otherPlayer.Character local root = otherCharacter and otherCharacter:FindFirstChild("HumanoidRootPart") local otherHumanoid = otherCharacter and otherCharacter:FindFirstChildOfClass("Humanoid") if root and otherHumanoid and otherHumanoid.Health > 0 then local targetPosition = root.Position / 3 local distance = (targetPosition - eyePosition).Magnitude if distance <= closestDistance then closestTarget = otherCharacter closestDistance = distance end end end end if not closestTarget then return end local targetRoot = closestTarget:FindFirstChild("HumanoidRootPart") if not targetRoot then return end local targetPosition = targetRoot.Position / 3 lastAttack = tick() attackCount += 1 if swingRemote then swingRemote:FireServer() end attackRemote:FireServer(closestTarget, { sprint = false, charge = 1, vt = Workspace:GetServerTimeNow(), dir = (targetPosition - eyePosition).Unit, eye = eyePosition, t = Workspace.DistributedGameTime, crit = true, n = attackCount }) end)