local LocalPlayer = game.GetService(game, "Players").LocalPlayer; local ReplicatedStorage = game.GetService(game, "ReplicatedStorage"); local Workspace = game.GetService(game, "Workspace"); local RunTimeItems = Workspace.RuntimeItems; do -- MAIN local Melee = {}; do function Melee.SwingMelee(Position, Weapon) local WeaponName = Weapon.Name; if not LocalPlayer.Character:FindFirstChild(WeaponName) then local CurrentTool = LocalPlayer.Character:FindFirstChildOfClass("Tool"); if CurrentTool then CurrentTool.Parent = LocalPlayer.Backpack end; LocalPlayer.Backpack[WeaponName].Parent = LocalPlayer.Character; end; ReplicatedStorage.Remotes.Tool.DropTool:FireServer(LocalPlayer.Character[WeaponName]); RunTimeItems.ChildAdded:Wait(); ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); -- dont mind the bunch of checks to ensure the fastest speed if RunTimeItems:FindFirstChild(WeaponName) then ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); end; task.delay(0.01, function() if RunTimeItems:FindFirstChild(WeaponName) then ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); end; end); task.delay(0.05, function() if RunTimeItems:FindFirstChild(WeaponName) then ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); end; end); task.delay(0.1, function() if RunTimeItems:FindFirstChild(WeaponName) then ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); end; end); task.delay(0.15, function() if RunTimeItems:FindFirstChild(WeaponName) then ReplicatedStorage.Remotes.Tool.PickUpTool:FireServer(RunTimeItems:FindFirstChild(WeaponName)); end; end); local SwingConnection; SwingConnection = LocalPlayer.Backpack.ChildAdded:Connect(function(Child) if Child.Name == WeaponName then local NewWeapon = Child; NewWeapon.Parent = LocalPlayer.Character; NewWeapon.SwingEvent:FireServer(CFrame.lookAt(LocalPlayer.Character.Head.Position, Position).LookVector); SwingConnection:Disconnect(); SwingConnection = nil; end; end); task.wait(); end; end; function getNearestTarget() -- used an older getnearesttarget local targ = nil local dist = 100 for i, v in pairs(workspace:GetDescendants()) do if (v:IsA("Humanoid") and v.Health > 0 and not game.Players:GetPlayerFromCharacter(v.Parent)) and v.Parent:FindFirstChild("HumanoidRootPart") and (v.Parent.HumanoidRootPart.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude < 10 and (v.Parent.HumanoidRootPart.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude < dist then dist = (v.Parent.HumanoidRootPart.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude targ = v.Parent end end return targ end function GetMelee(Player) local Weapon; for Index, Value in pairs(Player.Backpack:GetChildren()) do if Value:FindFirstChild("MeleeWeaponConfiguration") then Weapon = Value; end; end; local HoldingTool = Player.Character:FindFirstChildOfClass("Tool"); if HoldingTool and HoldingTool:FindFirstChild("MeleeWeaponConfiguration") then Weapon = HoldingTool; end; return Weapon; end while task.wait() do local NearestEnemy = getNearestTarget(); if (not NearestEnemy) then continue; end; if (not GetMelee(LocalPlayer)) then continue; end; Melee.SwingMelee(NearestEnemy.HumanoidRootPart.Position, GetMelee(LocalPlayer)); end; end;