Advertisement
avigeo

Auto Duel V2

Jan 17th, 2022
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2.  
  3.  
  4.  
  5. --ui
  6. function createStatusUI()
  7.     local statusUI = Instance.new("ScreenGui", plr.PlayerGui)
  8.     statusUI.ResetOnSpawn = false
  9.     statusLabel = Instance.new("TextButton", statusUI)
  10.     statusLabel.Size = UDim2.new(0.1,0,0.1,0)
  11.     statusLabel.Text = "Bot Disabled."
  12. end
  13. createStatusUI()
  14.  
  15. --
  16.  
  17. function dist(obj1, obj2)
  18.     return (obj1.Position - obj2.Position).magnitude
  19. end
  20.  
  21. --bot
  22.  
  23. local enemyAttackConnection
  24. local enemyParryConnection
  25.  
  26. function newCharacter(plrChar)
  27.     plrChar.ChildAdded:Connect(function(newChild)
  28.         statusLabel.Text = "Script executed, player found."
  29.         if newChild:FindFirstChild("combatData") then
  30.             statusLabel.Text = "Player lightsaber hooked."
  31.  
  32.             local plrLightsaber = newChild
  33.             local plrCombatData = plrLightsaber.combatData
  34.             local plrRemoteFolder = plrLightsaber.Assets.Events
  35.             local plrAttackRemote = plrRemoteFolder.attackStart
  36.             local plrCancelAttack = plrRemoteFolder.cancelAttack
  37.             local plrUpdateStance = plrRemoteFolder.updateStance
  38.             local plrTarget = plrCombatData.Target
  39.             local plrAttacking = plrCombatData.Attacking
  40.             local plrParrying = plrCombatData.Parrying
  41.  
  42.             plrTarget.Changed:Connect(function()
  43.                 statusLabel.Text = "Player enemy hooked."
  44.  
  45.                 --disconnect all previous enemy listeners
  46.                 if enemyAttackConnection then
  47.                     enemyAttackConnection:Disconnect()
  48.                     enemyAttackConnection = nil
  49.                 end
  50.                 if enemyParryConnection then
  51.                     enemyParryConnection:Disconnect()
  52.                     enemyParryConnection = nil
  53.                 end
  54.  
  55.                 --
  56.  
  57.                 if plrTarget.Value ~= nil then
  58.                     local enemyLightsaber = nil
  59.                     for _,child in pairs(plrTarget.Value:GetChildren()) do
  60.                         if child:IsA("Tool") then
  61.                             if child:FindFirstChild("combatData") then
  62.                                 enemyLightsaber = child
  63.                             end
  64.                         end
  65.                     end
  66.  
  67.                     if enemyLightsaber == nil then return end
  68.                     local enemyCombatData = enemyLightsaber.combatData
  69.                     local enemyAttacking = enemyCombatData.Attacking
  70.                     local enemyParrying = enemyCombatData.Parrying
  71.                     local enemyStance = enemyCombatData.Stance
  72.  
  73.                     enemyParryConnection = enemyParrying.Changed:Connect(function()
  74.                         if dist(enemyLightsaber.Parent.Head,plrLightsaber.Parent.Head) < 9.5 then
  75.                             if enemyParrying.Value == true then
  76.                                 statusLabel.Text = "Enemy attacking."
  77.                                 plrAttackRemote:FireServer(enemyStance.Value, false)
  78.                                 wait(0.1)
  79.                                 if enemyAttacking.Value == false then
  80.                                     plrCancelAttack:FireServer()
  81.                                     return
  82.                                 end
  83.                                 repeat
  84.                                     wait()
  85.                                 until plrAttacking.Value == false
  86.                                 plrUpdateStance:FireServer(enemyCombatData.Stance.Value, false)
  87.                                 plrAttackRemote:FireServer(enemyStance.Value-180, false)
  88.                             end
  89.                         end
  90.                     end)
  91.                 end
  92.             end)
  93.         end
  94.     end)
  95. end
  96.  
  97. plr.CharacterAdded:Connect(newCharacter)
  98.  
  99. --
  100.  
  101.  
  102. --for first time joining the game
  103. if plr.Character ~= nil then
  104.     newCharacter(plr.Character)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement