Classic Sword AI/Bot, Auto fight in sword games

Script Credit :- 1x1x1x1C00lKid
Features

Auto fight

execute when you are alive (if you die you have to execute again) and with X you toggle the AI

Script
--BROUGHT TO YOU BY RobloxScripter.com!--

local char = game:GetService("Players").LocalPlayer.Character local pa = Instance.new("Folder", workspace) function allplayers() for i,v in pairs(game:GetService("Players"):GetChildren()) do v.Character.Parent = pa end return pa end function FindBestAngle(p1, p2, p3) local v1 = RaycastParams.new(); v1.FilterType = Enum.RaycastFilterType.Blacklist; local Filter = Instance.new("Folder", workspace) local Map = Instance.new("Folder", workspace) v1.FilterDescendantsInstances = { p1, Filter, p3, table.unpack(p2.Humanoid:GetAccessories()), Map }; local v2 = {}; table.insert(v2, { workspace:Raycast(p1["Right Arm"].Position, p1.PrimaryPart.CFrame.LookVector * 10, v1), 0 }); table.insert(v2, { workspace:Raycast(p1["Right Arm"].Position, (p1.PrimaryPart.CFrame * CFrame.Angles(0, -0.017453292519943295, 0)).LookVector.Unit * 10, v1), -1 }); table.insert(v2, { workspace:Raycast(p1["Right Arm"].Position, (p1.PrimaryPart.CFrame * CFrame.Angles(0, 0.017453292519943295, 0)).LookVector.Unit * 10, v1), 1 }); table.insert(v2, { workspace:Raycast(p1["Right Arm"].Position, (p1.PrimaryPart.CFrame * CFrame.Angles(0, 0.03490658503988659, 0)).LookVector.Unit * 10, v1), 2 }); table.insert(v2, { workspace:Raycast(p1["Right Arm"].Position, (p1.PrimaryPart.CFrame * CFrame.Angles(0, -0.03490658503988659, 0)).LookVector.Unit * 10, v1), -2 }); Filter:ClearAllChildren(); Filter:Destroy(); Map:Destroy(); local v3 = math.huge; local v4 = 0; for v5, v6 in pairs(v2) do if v6[1] then local l__Magnitude__7 = (p1["Right Arm"].Position - v6[1].Position).Magnitude; if l__Magnitude__7 < v3 then v3 = l__Magnitude__7; v4 = v6[2]; local l__Position__8 = v6.Position; end; end; end; return v4; end; function SideCast(p12) local v21 = RaycastParams.new(); v21.FilterType = Enum.RaycastFilterType.Blacklist; v21.FilterDescendantsInstances = {allplayers()}; local v22 = 0; for v23 = 1, 10 do local v24 = workspace:Raycast(p12.PrimaryPart.Position, (p12.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(v22), 0)).LookVector * 8, v21); v22 = v22 + 36; if v24 then return v24; end; end; end function GetRetreatDirection(p9, p10, p11) local v13 = p9.PrimaryPart.Position - p10.PrimaryPart.Position; local v14 = RaycastParams.new(); v14.FilterType = Enum.RaycastFilterType.Blacklist; v14.FilterDescendantsInstances = {allplayers()}; local v15 = -135; local v16 = 0; local v17 = nil; for v18 = 1, 10 do local v19 = workspace:Raycast(p9.PrimaryPart.Position, (CFrame.lookAt(p9.PrimaryPart.Position, p9.PrimaryPart.Position + v13) * CFrame.Angles(0, math.rad(v15), 0)).LookVector * p11, v14); if v19 then local l__Magnitude__20 = (v19.Position - p10.PrimaryPart.Position).Magnitude; if v16 < l__Magnitude__20 then v17 = v19.Position; v16 = l__Magnitude__20; end; end; v15 = v15 + 27; end; return v17; end local function GetClosestEnemy(p4) local v2 = nil; local v3 = math.huge; for v4, v5 in pairs(game:GetService("Players"):GetChildren()) do v5 = v5.Character if v5 ~= p4 then local l__Magnitude__6 = (v5.PrimaryPart.Position - p4.PrimaryPart.Position).Magnitude; if l__Magnitude__6 < v3 then v3 = l__Magnitude__6; v2 = v5; end; end; end; return v2; end function GetClosestPart(p7, p8) local v7 = nil; local v8 = math.huge; for v9, v10 in pairs(p8:GetChildren()) do if v10:IsA("BasePart") then local v11 = Vector3.new(0, 0, 0); if v10.Name == "Right Arm" then v11 = p8.PrimaryPart.CFrame.LookVector * 3; end; local l__Magnitude__12 = (p7 - (v10.Position + v11)).Magnitude; if l__Magnitude__12 0 do v10 = v10 + game:GetService("RunService").RenderStepped:Wait(); local v14 = GetClosestEnemy(p1); if v14 then local v15 = GetClosestPart(v9.Handle.Position, v14); local v16 = v14:FindFirstChildOfClass("Tool"); local v17 = false; if v16 and v16.Grip == Grips.Out then if v13 == false then v12 = v10; end; v13 = true; end; if v9.Grip ~= Grips.Out then v17 = true; end; local v18 = v14.Humanoid.Health < p1.Humanoid.Health; local l__Position__19 = p1.PrimaryPart.Position; local l__Position__20 = v14.PrimaryPart.Position; local v21 = math.sqrt((l__Position__19.X - l__Position__20.X) ^ 2 + (l__Position__19.Z - l__Position__20.Z) ^ 2); local v22 = GetDistance(p1, v14); local v23 = math.abs(v14.PrimaryPart.Position.Y - p1.PrimaryPart.Position.Y) 6 and v16 and v14 then local l__Position__25 = l__PrimaryPart__8.Position; local v26 = v16.Handle.Position + v14.PrimaryPart.CFrame.LookVector * v16.Handle.Size.Y * 2.2; p1:SetPrimaryPartCFrame(CFrame.lookAt(l__Position__25, v26 - Vector3.new(0, v26.Y - l__Position__25.Y, 0)) * CFrame.Angles(0, 0.30543261909900765, 0)); else if v9.Parent ~= p1 then break end; v9.Parent = p1; p1:SetPrimaryPartCFrame(CFrame.lookAt(l__PrimaryPart__8.Position, v15.Position - Vector3.new(0, v15.Position.Y - l__PrimaryPart__8.Position.Y, 0)) * CFrame.Angles(0, 0.30543261909900765, 0)); local v27 = 0; local v28 = v27; for v29 = 1, 10 do v27 = v27 + FindBestAngle(p1, v14, v16); if v28 == v27 then if v18 then local v30 = v27 + math.random(-10, 10); else v30 = v27 + math.random(-2, 2); end; p1:SetPrimaryPartCFrame(CFrame.lookAt(l__PrimaryPart__8.Position, v15.Position - Vector3.new(0, v15.Position.Y - l__PrimaryPart__8.Position.Y, 0)) * CFrame.Angles(0, math.rad(17.5 + v30), 0)); break; end; v28 = v27; p1:SetPrimaryPartCFrame(CFrame.lookAt(l__PrimaryPart__8.Position, v15.Position - Vector3.new(0, v15.Position.Y - l__PrimaryPart__8.Position.Y, 0)) * CFrame.Angles(0, math.rad(17.5 + v27), 0)); end; end; local v31 = ((p1.PrimaryPart.Position - v14.PrimaryPart.Position).Unit - v14.Humanoid.MoveDirection).Magnitude 0.1 and not (v10 - v12 0.05 then v34 = v34 - 2; end; if v10 - v11 > 0.5 then v34 = v34 + 2; end; if v21 8 and p1.Humanoid.Health < v14.Humanoid.Health then v34 = v34 + 10; end; local v35 = -v14.PrimaryPart.CFrame.RightVector; if v18 and v23 then v35 = v35 * 3; v34 = 2; end; if SideCast(v14) or v9.Grip == Grips.Up then v35 = Vector3.new(0, 0, 0); end; local v36 = l__Position__24 - (l__Position__24 - l__PrimaryPart__8.Position).Unit * v34 + v35; if v18 then end; if v22 < v34 then if GetRetreatDirection(p1, v14, 10) and v31 then l__Humanoid__7:MoveTo((GetRetreatDirection(p1, v14, 100))); else l__Humanoid__7:MoveTo(v36); end; else l__Humanoid__7:MoveTo(v36); end; end; end; end; game:GetService"UserInputService".InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.X then AI(char) end end)

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors