Advertisement
KenshiOfficial

Autofarm school thugs

Sep 29th, 2024
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. -- Create the GUI
  2. local Players = game:GetService("Players")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4.  
  5. local gui = Instance.new("ScreenGui")
  6. gui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
  7. gui.DisplayOrder = 10
  8.  
  9. local frame = Instance.new("Frame")
  10. frame.Size = UDim2.new(0, 200, 0, 200)
  11. frame.Position = UDim2.new(0, 30, 0.5, -100)
  12. frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  13. frame.BorderSizePixel = 2
  14. frame.Parent = gui
  15.  
  16. local targetLabel = Instance.new("TextLabel")
  17. targetLabel.Size = UDim2.new(1, 0, 0, 30)
  18. targetLabel.Position = UDim2.new(0, 0, 0, 0)
  19. targetLabel.Text = "Target: None"
  20. targetLabel.BackgroundColor3 = Color3.fromRGB(200, 200, 200)
  21. targetLabel.Parent = frame
  22.  
  23. local startButton = Instance.new("TextButton")
  24. startButton.Size = UDim2.new(0, 80, 0, 30)
  25. startButton.Position = UDim2.new(0.1, 0, 0.3, 0)
  26. startButton.Text = "Start Hitting"
  27. startButton.Parent = frame
  28.  
  29. local stopButton = Instance.new("TextButton")
  30. stopButton.Size = UDim2.new(0, 80, 0, 30)
  31. stopButton.Position = UDim2.new(0.1, 0, 0.6, 0)
  32. stopButton.Text = "Stop Hitting"
  33. stopButton.Parent = frame
  34.  
  35. -- Teleport buttons
  36. local teleportOnButton = Instance.new("TextButton")
  37. teleportOnButton.Size = UDim2.new(0, 80, 0, 30)
  38. teleportOnButton.Position = UDim2.new(0.1, 0, 0.9, 0)
  39. teleportOnButton.Text = "Teleport On"
  40. teleportOnButton.Parent = frame
  41.  
  42. local teleportOffButton = Instance.new("TextButton")
  43. teleportOffButton.Size = UDim2.new(0, 80, 0, 30)
  44. teleportOffButton.Position = UDim2.new(0.5, 0, 0.9, 0)
  45. teleportOffButton.Text = "Teleport Off"
  46. teleportOffButton.Parent = frame
  47.  
  48. local scriptRunning = false
  49. local teleportEnabled = true
  50. local currentTarget = nil
  51. local player = Players.LocalPlayer
  52.  
  53. local function firePunchEvent(targetName)
  54. local args = {
  55. [1] = 4,
  56. [2] = workspace:WaitForChild("Characters"):WaitForChild(targetName)
  57. }
  58. ReplicatedStorage:WaitForChild("MainEvents"):WaitForChild("PUNCHEVENT"):FireServer(unpack(args))
  59. end
  60.  
  61. local function findClosestPlayer()
  62. local closestPlayer = nil
  63. local closestDistance = math.huge
  64.  
  65. for _, otherPlayer in pairs(Players:GetPlayers()) do
  66. if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  67. local distance = (player.Character.HumanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).magnitude
  68. if distance < closestDistance then
  69. closestDistance = distance
  70. closestPlayer = otherPlayer
  71. end
  72. end
  73. end
  74.  
  75. return closestPlayer
  76. end
  77.  
  78. local function updateTarget()
  79. local closestPlayer = findClosestPlayer()
  80. if closestPlayer then
  81. currentTarget = closestPlayer.Name
  82. targetLabel.Text = "Target: " .. currentTarget
  83. else
  84. currentTarget = nil
  85. targetLabel.Text = "Target: None"
  86. end
  87. end
  88.  
  89. local function teleportToTarget(target)
  90. local targetCharacter = Players:FindFirstChild(target) and Players[target].Character
  91. if targetCharacter and targetCharacter:FindFirstChild("HumanoidRootPart") then
  92. player.Character:MoveTo(targetCharacter.HumanoidRootPart.Position)
  93. end
  94. end
  95.  
  96. startButton.MouseButton1Click:Connect(function()
  97. updateTarget()
  98. if currentTarget then
  99. scriptRunning = true
  100. while scriptRunning do
  101. -- Check if the current target is alive
  102. local targetCharacter = Players:FindFirstChild(currentTarget) and Players[currentTarget].Character
  103. if targetCharacter and targetCharacter:FindFirstChild("Humanoid") and targetCharacter.Humanoid.Health > 0 then
  104. firePunchEvent(currentTarget)
  105. if teleportEnabled then
  106. teleportToTarget(currentTarget) -- Teleport to the target if enabled
  107. end
  108. else
  109. -- Target is dead or doesn't exist, find a new target
  110. updateTarget()
  111. end
  112. wait(5) -- Wait for 5 seconds
  113. end
  114. end
  115. end)
  116.  
  117. stopButton.MouseButton1Click:Connect(function()
  118. scriptRunning = false
  119. end)
  120.  
  121. teleportOnButton.MouseButton1Click:Connect(function()
  122. teleportEnabled = true
  123. end)
  124.  
  125. teleportOffButton.MouseButton1Click:Connect(function()
  126. teleportEnabled = false
  127. end)
  128.  
  129. -- Update target on mouse click
  130. Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
  131. updateTarget()
  132. end)
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement