BloodOfDexTeR

roblox fencing bot

Jun 7th, 2020
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. local virtualUser = game:GetService("VirtualUser")
  2. local silent = false
  3. local player = game.Players.LocalPlayer
  4. local matRegion = Region3.new(Vector3.new(-53, 6, 73), Vector3.new(11, 50, 145))
  5. local character
  6. local root
  7.  
  8. local autoAttacking = true
  9.  
  10. local function validatePlayer(cplayer)
  11. if not cplayer or not cplayer.Character or cplayer == player then
  12. return false
  13. end
  14.  
  15. local humanoid = cplayer.Character:FindFirstChild("Humanoid")
  16.  
  17. if humanoid and humanoid.Health > 0 then
  18. return true
  19. else
  20. return false
  21. end
  22. end
  23.  
  24. local function findNearestPlayer(position)
  25. local lowest = math.huge -- Range
  26. local nearestPlayer
  27. local partsInRegion = workspace:FindPartsInRegion3(matRegion)
  28. local playersInRegion = {}
  29.  
  30. for i = 1, #partsInRegion do
  31. if game.Players:GetPlayerFromCharacter(partsInRegion[i].Parent) then
  32. table.insert(playersInRegion, game.Players:GetPlayerFromCharacter(partsInRegion[i].Parent))
  33. end
  34. end
  35.  
  36. for _, playerInRegion in pairs(playersInRegion) do
  37. if validatePlayer(playerInRegion) then
  38. local distance = playerInRegion:DistanceFromCharacter(position)
  39.  
  40. if distance < lowest then
  41. lowest = distance
  42. nearestPlayer = playerInRegion
  43. end
  44. end
  45. end
  46.  
  47. return nearestPlayer
  48. end
  49.  
  50. local function chat(text)
  51. if not silent then
  52. game.ReplicatedStorage.DefaultChatSystemChatEvents.SayMessageRequest:FireServer("[BOT] ".. text, "All")
  53. end
  54. end
  55.  
  56. local function initLoop()
  57. while autoAttacking do
  58. local nearestPlayer = findNearestPlayer(root.Position)
  59.  
  60. if nearestPlayer then
  61. character.Humanoid:MoveTo(nearestPlayer.Character.HumanoidRootPart.Position, nearestPlayer.Character.HumanoidRootPart)
  62. character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, Vector3.new(nearestPlayer.Character.HumanoidRootPart.Position.X, character.HumanoidRootPart.Position.Y, nearestPlayer.Character.HumanoidRootPart.Position.Z));
  63.  
  64. if (root.Position - nearestPlayer.Character.HumanoidRootPart.Position).magnitude <= 25 then
  65. virtualUser:ClickButton1(Vector2.new())
  66. wait(0.05)
  67. virtualUser:ClickButton1(Vector2.new())
  68. end
  69. end
  70. wait()
  71. end
  72. end
  73.  
  74. local function spawnBot()
  75. wait(0.1)
  76.  
  77. if autoAttacking and character then
  78. root.CFrame = CFrame.new(math.random(-39, 0), 6, math.random(88, 131))
  79.  
  80. local foil = player.Backpack:FindFirstChild("Foil")
  81. if foil then
  82. player.Character.Humanoid:EquipTool(foil)
  83. for i,v in pairs(game:GetService'Players'.LocalPlayer.Character:GetChildren())do
  84. if v:isA("Tool") then
  85. a=Instance.new("SelectionBox",v.Handle)
  86. a.Adornee=v.Handle
  87. v.Handle.Size=Vector3.new(2,0.5,8.7) --Change reach size
  88. v.GripPos=Vector3.new(0,0,0)
  89. game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
  90. end
  91. end
  92. player.Character.Humanoid:EquipTool(foil)
  93. end
  94.  
  95. initLoop()
  96. end
  97. end
  98.  
  99. local function chatted(msg)
  100. if msg == "!boton" then
  101. autoAttacking = true
  102. chat('autoAttacking = true spawnBot() end')
  103. spawnBot()
  104. end
  105.  
  106. if msg == "!botoff" then
  107. autoAttacking = false
  108. chat('autoAttacking = false')
  109. end
  110. end
  111.  
  112. local function characterAdded(char)
  113. character = char
  114. root = character:WaitForChild("HumanoidRootPart")
  115.  
  116. if autoAttacking then
  117. spawnBot()
  118. end
  119. end
  120.  
  121. game.Players.LocalPlayer.Chatted:Connect(chatted)
  122. game.Players.LocalPlayer.CharacterAdded:Connect(characterAdded)
  123. virtualUser:CaptureController()
  124.  
  125. local success, _ = pcall(function()
  126. local asyncSpawn = coroutine.wrap(function()
  127. characterAdded(player.Character)
  128. end)
  129.  
  130. asyncSpawn()
  131. end)
  132.  
  133. if not success then
  134. chat("Bot failed to load. Is character loaded?")
  135. else
  136. chat('Hello, I am an automated sword-fighting bot') --chat on activate
  137. end
Add Comment
Please, Sign In to add comment