Advertisement
aesnike

BEN

Oct 26th, 2024 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.84 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local LocalPlayer = Players.LocalPlayer
  3. local Character
  4. local targetNPC
  5. local targetCoin
  6.  
  7. -- Customizable parameters (with default values)
  8. local delay = 0.5
  9. local offset = Vector3.new(0, 9, 0)
  10. local waitTimeIfNoMobs = 2
  11. local coinStayDuration = 1
  12. local mobRange = 20 -- Range for key press activation
  13.  
  14. -- Save file path (relative to the exploit's workspace)
  15. local saveFilePath = "settings.txt"
  16.  
  17. -- Function to load settings from the save file
  18. local function loadSettings()
  19. local success, data = pcall(function()
  20. return game:GetService("HttpService"):JSONDecode(readfile(saveFilePath))
  21. end)
  22.  
  23. if success and data then
  24. delay = data.delay or delay
  25. offset = Vector3.new(data.offsetX or offset.X, data.offsetY or offset.Y, data.offsetZ or offset.Z)
  26. waitTimeIfNoMobs = data.waitTimeIfNoMobs or waitTimeIfNoMobs
  27. coinStayDuration = data.coinStayDuration or coinStayDuration
  28. mobRange = data.mobRange or mobRange
  29. end
  30. end
  31.  
  32. -- Function to save settings to the save file
  33. local function saveSettings()
  34. local data = {
  35. delay = delay,
  36. offsetX = offset.X,
  37. offsetY = offset.Y,
  38. offsetZ = offset.Z,
  39. waitTimeIfNoMobs = waitTimeIfNoMobs,
  40. coinStayDuration = coinStayDuration,
  41. mobRange = mobRange
  42. }
  43.  
  44. local success, message = pcall(function()
  45. writefile(saveFilePath, game:GetService("HttpService"):JSONEncode(data))
  46. end)
  47.  
  48. if not success then
  49. warn("Error saving settings:", message)
  50. end
  51. end
  52.  
  53. -- Load settings on script start
  54. loadSettings()
  55.  
  56. -- Remote Event setup
  57. local dataRemoteEvent = game:GetService("ReplicatedStorage").dataRemoteEvent
  58. local changeStartValueRemote = game:GetService("ReplicatedStorage").remotes.changeStartValue
  59. local retryVote = LocalPlayer.PlayerGui:WaitForChild("RetryVote")
  60. local revivePrompt = LocalPlayer.PlayerGui:WaitForChild("RevivePrompt")
  61. local startButton = LocalPlayer.PlayerGui:WaitForChild("HUD"):WaitForChild("Mobile"):WaitForChild("StartButton")
  62.  
  63. local voteArgs = {
  64. [1] = {
  65. [1] = {
  66. ["\3"] = "vote",
  67. ["vote"] = true
  68. },
  69. [2] = "."
  70. }
  71. }
  72.  
  73. local reviveArgs = {
  74. [1] = {
  75. [1] = {
  76. ["\3"] = "closeRevive"
  77. },
  78. [2] = "\13"
  79. }
  80. }
  81.  
  82. -- Function to find the nearest NPC
  83. local function findNearestNPC()
  84. local nearestNPC = nil
  85. local nearestDistance = math.huge
  86.  
  87. Character = LocalPlayer.Character
  88. if not Character or not Character.HumanoidRootPart then return end
  89.  
  90. for _, folder in ipairs(workspace:GetChildren()) do
  91. if folder:IsA("Folder") then
  92. for _, child in ipairs(folder:GetChildren()) do
  93. if child:FindFirstChild("enemyFolder") then
  94. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  95. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  96. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  97. if distance < nearestDistance then
  98. nearestDistance = distance
  99. nearestNPC = npc
  100. end
  101. end
  102. end
  103. end
  104. end
  105. end
  106. end
  107. return nearestNPC
  108. end
  109.  
  110. -- Function to find the nearest coin
  111. local function findNearestCoin()
  112. local nearestCoin = nil
  113. local nearestDistance = math.huge
  114.  
  115. Character = LocalPlayer.Character
  116. if not Character or not Character.HumanoidRootPart then return end
  117.  
  118. for _, descendant in ipairs(workspace:GetDescendants()) do
  119. if descendant.Name == "Coin" and descendant:IsA("BasePart") then
  120. local distance = (Character.HumanoidRootPart.Position - descendant.Position).Magnitude
  121. if distance < nearestDistance then
  122. nearestDistance = distance
  123. nearestCoin = descendant
  124. end
  125. end
  126. end
  127. return nearestCoin
  128. end
  129.  
  130. local coinTouchedTime = 0
  131.  
  132. local function stayOnTopOfTarget()
  133. -- Prioritize coins
  134. if targetCoin and targetCoin.Parent then
  135. if Character and Character:FindFirstChild("HumanoidRootPart") then
  136. Character.HumanoidRootPart.CFrame = targetCoin.CFrame
  137.  
  138. if coinTouchedTime == 0 then
  139. coinTouchedTime = tick()
  140. end
  141.  
  142. if tick() - coinTouchedTime > coinStayDuration then
  143. targetCoin = nil
  144. coinTouchedTime = 0
  145. end
  146. end
  147. elseif not targetNPC or not targetNPC.Parent or not targetNPC:FindFirstChild("HumanoidRootPart") then
  148. targetNPC = findNearestNPC()
  149. if not targetNPC then
  150. wait(waitTimeIfNoMobs)
  151. return
  152. end
  153. elseif Character and Character:FindFirstChild("HumanoidRootPart") and targetNPC and targetNPC:FindFirstChild("HumanoidRootPart") then
  154. local npcPosition = targetNPC.HumanoidRootPart.Position
  155. local lookVector = (npcPosition - Character.HumanoidRootPart.Position).Unit
  156. local cframe = CFrame.new(npcPosition + offset, npcPosition)
  157. Character.HumanoidRootPart.CFrame = cframe
  158. end
  159. end
  160.  
  161. -- CharacterAdded Connection
  162. LocalPlayer.CharacterAdded:Connect(function(newCharacter)
  163. Character = newCharacter
  164. targetNPC = nil
  165. targetCoin = nil
  166. wait(1)
  167. end)
  168.  
  169. -- Key press logic
  170. local UserInputService = game:GetService("UserInputService")
  171. local VirtualInputManager = game:GetService("VirtualInputManager")
  172. local lastKeyPress = 0
  173. local keyPressCooldown = 0.5
  174.  
  175. local function isNearMobs(range)
  176. Character = LocalPlayer.Character
  177. if not Character or not Character.HumanoidRootPart then return false end
  178.  
  179. for _, folder in ipairs(workspace:GetChildren()) do
  180. if folder:IsA("Folder") then
  181. for _, child in ipairs(folder:GetChildren()) do
  182. if child:FindFirstChild("enemyFolder") then
  183. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  184. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  185. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  186. if distance <= range then
  187. return true
  188. end
  189. end
  190. end
  191. end
  192. end
  193. end
  194. end
  195. return false
  196. end
  197.  
  198. local function pressKey(key)
  199. VirtualInputManager:SendKeyEvent(true, key, false, nil)
  200. task.wait()
  201. VirtualInputManager:SendKeyEvent(false, key, false, nil)
  202. end
  203.  
  204. -- Main Heartbeat loop
  205. local lastTeleportTime = 0
  206. game:GetService("RunService").Heartbeat:Connect(function()
  207. stayOnTopOfTarget()
  208.  
  209. local currentTime = tick()
  210. if currentTime - lastTeleportTime >= delay then
  211. lastTeleportTime = currentTime
  212. targetCoin = findNearestCoin()
  213. if not targetCoin then
  214. targetNPC = findNearestNPC()
  215. end
  216.  
  217. -- Fire remote events based on GUI state
  218. if retryVote and retryVote.Enabled then
  219. dataRemoteEvent:FireServer(unpack(voteArgs))
  220. end
  221.  
  222. if revivePrompt and revivePrompt.Enabled then
  223. dataRemoteEvent:FireServer(unpack(reviveArgs))
  224. end
  225.  
  226. -- Fire changeStartValue if StartButton is visible
  227. if startButton.Visible then
  228. changeStartValueRemote:FireServer()
  229. end
  230.  
  231. -- Key press logic
  232. if isNearMobs(mobRange) and tick() - lastKeyPress >= keyPressCooldown then -- Use mobRange
  233. pressKey("E")
  234. pressKey("Q")
  235. lastKeyPress = tick()
  236. end
  237. end
  238. end)
  239.  
  240. -- Initialize
  241. targetCoin = findNearestCoin()
  242. if not targetCoin then
  243. targetNPC = findNearestNPC()
  244. end
  245.  
  246. -- Separate loop to send animation data
  247. coroutine.wrap(function()
  248. while true do
  249. local args = {
  250. [1] = {
  251. [1] = {
  252. ["animationLength"] = 0,
  253. ["sentAt"] = tick()
  254. },
  255. [2] = "G"
  256. }
  257. }
  258.  
  259. game:GetService("ReplicatedStorage").dataRemoteEvent:FireServer(unpack(args))
  260. wait(0)
  261. end
  262. end)()
  263.  
  264. -- Mobile GUI creation
  265. local MobileGui = Instance.new("ScreenGui")
  266. MobileGui.Name = "SettingsGUI"
  267. MobileGui.Parent = LocalPlayer.PlayerGui
  268.  
  269. -- Delay setting
  270. local DelayLabel = Instance.new("TextLabel")
  271. DelayLabel.Text = "Delay:"
  272. DelayLabel.Position = UDim2.new(0.1, 0, 0.1, 0)
  273. DelayLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  274. DelayLabel.Parent = MobileGui
  275.  
  276. local DelayTextBox = Instance.new("TextBox")
  277. DelayTextBox.Text = tostring(delay)
  278. DelayTextBox.Position = UDim2.new(0.3, 0, 0.1, 0)
  279. DelayTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  280. DelayTextBox.Parent = MobileGui
  281.  
  282. DelayTextBox.FocusLost:Connect(function(enterPressed)
  283. if enterPressed then
  284. local newDelay = tonumber(DelayTextBox.Text)
  285. if newDelay then
  286. delay = newDelay
  287. saveSettings()
  288. end
  289. end
  290. end)
  291.  
  292. -- Offset X setting
  293. local OffsetXLabel = Instance.new("TextLabel")
  294. OffsetXLabel.Text = "Offset X:"
  295. OffsetXLabel.Position = UDim2.new(0.1, 0, 0.16, 0)
  296. OffsetXLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  297. OffsetXLabel.Parent = MobileGui
  298.  
  299. local OffsetXTextBox = Instance.new("TextBox")
  300. OffsetXTextBox.Text = tostring(offset.X)
  301. OffsetXTextBox.Position = UDim2.new(0.3, 0, 0.16, 0)
  302. OffsetXTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  303. OffsetXTextBox.Parent = MobileGui
  304.  
  305. OffsetXTextBox.FocusLost:Connect(function(enterPressed)
  306. if enterPressed then
  307. local newOffsetX = tonumber(OffsetXTextBox.Text)
  308. if newOffsetX then
  309. offset = Vector3.new(newOffsetX, offset.Y, offset.Z)
  310. saveSettings()
  311. end
  312. end
  313. end)
  314.  
  315. -- Offset Y setting
  316. local OffsetYLabel = Instance.new("TextLabel")
  317. OffsetYLabel.Text = "Offset Y:"
  318. OffsetYLabel.Position = UDim2.new(0.1, 0, 0.22, 0)
  319. OffsetYLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  320. OffsetYLabel.Parent = MobileGui
  321.  
  322. local OffsetYTextBox = Instance.new("TextBox")
  323. OffsetYTextBox.Text = tostring(offset.Y)
  324. OffsetYTextBox.Position = UDim2.new(0.3, 0, 0.22, 0)
  325. OffsetYTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  326. OffsetYTextBox.Parent = MobileGui
  327.  
  328. OffsetYTextBox.FocusLost:Connect(function(enterPressed)
  329. if enterPressed then
  330. local newOffsetY = tonumber(OffsetYTextBox.Text)
  331. if newOffsetY then
  332. offset = Vector3.new(offset.X, newOffsetY, offset.Z)
  333. saveSettings()
  334. end
  335. end
  336. end)
  337.  
  338. -- Offset Z setting
  339. local OffsetZLabel = Instance.new("TextLabel")
  340. OffsetZLabel.Text = "Offset Z:"
  341. OffsetZLabel.Position = UDim2.new(0.1, 0, 0.28, 0)
  342. OffsetZLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  343. OffsetZLabel.Parent = MobileGui
  344.  
  345. local OffsetZTextBox = Instance.new("TextBox")
  346. OffsetZTextBox.Text = tostring(offset.Z)
  347. OffsetZTextBox.Position = UDim2.new(0.3, 0, 0.28, 0)
  348. OffsetZTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  349. OffsetZTextBox.Parent = MobileGui
  350.  
  351. OffsetZTextBox.FocusLost:Connect(function(enterPressed)
  352. if enterPressed then
  353. local newOffsetZ = tonumber(OffsetZTextBox.Text)
  354. if newOffsetZ then
  355. offset = Vector3.new(offset.X, offset.Y, newOffsetZ)
  356. saveSettings()
  357. end
  358. end
  359. end)
  360.  
  361. -- Wait Time If No Mobs setting
  362. local WaitTimeLabel = Instance.new("TextLabel")
  363. WaitTimeLabel.Text = "Wait Time (No Mobs):"
  364. WaitTimeLabel.Position = UDim2.new(0.1, 0, 0.34, 0)
  365. WaitTimeLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  366. WaitTimeLabel.Parent = MobileGui
  367.  
  368. local WaitTimeTextBox = Instance.new("TextBox")
  369. WaitTimeTextBox.Text = tostring(waitTimeIfNoMobs)
  370. WaitTimeTextBox.Position = UDim2.new(0.3, 0, 0.34, 0)
  371. WaitTimeTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  372. WaitTimeTextBox.Parent = MobileGui
  373.  
  374. WaitTimeTextBox.FocusLost:Connect(function(enterPressed)
  375. if enterPressed then
  376. local newWaitTime = tonumber(WaitTimeTextBox.Text)
  377. if newWaitTime then
  378. waitTimeIfNoMobs = newWaitTime
  379. saveSettings()
  380. end
  381. end
  382. end)
  383.  
  384. -- Coin Stay Duration setting
  385. local CoinDurationLabel = Instance.new("TextLabel")
  386. CoinDurationLabel.Text = "Coin Stay Duration:"
  387. CoinDurationLabel.Position = UDim2.new(0.1, 0, 0.4, 0)
  388. CoinDurationLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  389. CoinDurationLabel.Parent = MobileGui
  390.  
  391. local CoinDurationTextBox = Instance.new("TextBox")
  392. CoinDurationTextBox.Text = tostring(coinStayDuration)
  393. CoinDurationTextBox.Position = UDim2.new(0.3, 0, 0.4, 0)
  394. CoinDurationTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  395. CoinDurationTextBox.Parent = MobileGui
  396.  
  397. CoinDurationTextBox.FocusLost:Connect(function(enterPressed)
  398. if enterPressed then
  399. local newDuration = tonumber(CoinDurationTextBox.Text)
  400. if newDuration then
  401. coinStayDuration = newDuration
  402. saveSettings()
  403. end
  404. end
  405. end)
  406.  
  407. -- Mob Range setting
  408. local MobRangeLabel = Instance.new("TextLabel")
  409. MobRangeLabel.Text = "Mob Range:"
  410. MobRangeLabel.Position = UDim2.new(0.1, 0, 0.46, 0)
  411. MobRangeLabel.Size = UDim2.new(0.2, 0, 0.05, 0)
  412. MobRangeLabel.Parent = MobileGui
  413.  
  414. local MobRangeTextBox = Instance.new("TextBox")
  415. MobRangeTextBox.Text = tostring(mobRange)
  416. MobRangeTextBox.Position = UDim2.new(0.3, 0, 0.46, 0)
  417. MobRangeTextBox.Size = UDim2.new(0.2, 0, 0.05, 0)
  418. MobRangeTextBox.Parent = MobileGui
  419.  
  420. MobRangeTextBox.FocusLost:Connect(function(enterPressed)
  421. if enterPressed then
  422. local newRange = tonumber(MobRangeTextBox.Text)
  423. if newRange then
  424. mobRange = newRange
  425. saveSettings()
  426. end
  427. end
  428. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement