Advertisement
aesnike

Ben script

Oct 25th, 2024 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local LocalPlayer = Players.LocalPlayer
  3. local Character
  4. local targetNPC
  5.  
  6. local noclipEnabled = false
  7.  
  8. -- Customizable parameters
  9. local delay = 0.5 -- Delay between teleports (in seconds)
  10. local offset = Vector3.new(0, 9, 0) -- Vertical offset above the NPC
  11. local noMobWaitTime = 3 -- Wait time (in seconds) if no mobs are found
  12.  
  13. -- Remote Event setup
  14. local dataRemoteEvent = game:GetService("ReplicatedStorage").dataRemoteEvent
  15. local retryVote = LocalPlayer.PlayerGui.RetryVote
  16. local revivePrompt = LocalPlayer.PlayerGui.RevivePrompt
  17.  
  18. -- Function to toggle noclip
  19. local function toggleNoclip()
  20. noclipEnabled = not noclipEnabled
  21. if Character and Character.Humanoid then
  22. Character.Humanoid:ChangeState(noclipEnabled and 11 or Enum.HumanoidStateType.Running)
  23. end
  24. end
  25.  
  26. -- Connect noclip toggle to the "o" key
  27. game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
  28. if not processed and input.KeyCode == Enum.KeyCode.O then
  29. toggleNoclip()
  30. end
  31. end)
  32.  
  33. local function findNearestNPC()
  34. local nearestNPC = nil
  35. local nearestDistance = math.huge
  36.  
  37. Character = LocalPlayer.Character
  38. if not Character or not Character.HumanoidRootPart then return end
  39.  
  40. for _, folder in ipairs(workspace:GetChildren()) do
  41. if folder:IsA("Folder") then
  42. for _, child in ipairs(folder:GetChildren()) do
  43. if child:FindFirstChild("enemyFolder") then
  44. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  45. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  46. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  47. if distance < nearestDistance then
  48. nearestDistance = distance
  49. nearestNPC = npc
  50. end
  51. end
  52. end
  53. end
  54. end
  55. end
  56. end
  57. return nearestNPC
  58. end
  59.  
  60. local function stayOnTopOfNPC()
  61. if not targetNPC or not targetNPC.Parent or not targetNPC:FindFirstChild("HumanoidRootPart") then
  62. targetNPC = findNearestNPC()
  63. end
  64.  
  65. Character = LocalPlayer.Character
  66. if Character and Character:FindFirstChild("HumanoidRootPart") and targetNPC and targetNPC:FindFirstChild("HumanoidRootPart") then
  67. local npcPosition = targetNPC.HumanoidRootPart.Position
  68. local lookVector = (npcPosition - Character.HumanoidRootPart.Position).Unit
  69. local cframe = CFrame.new(npcPosition + offset, npcPosition)
  70. Character.HumanoidRootPart.CFrame = cframe
  71. end
  72. end
  73.  
  74. -- CharacterAdded Connection
  75. LocalPlayer.CharacterAdded:Connect(function(newCharacter)
  76. Character = newCharacter
  77. targetNPC = nil
  78. wait(1)
  79. end)
  80.  
  81. local lastTeleportTime = 0
  82. local lastMobCheckTime = 0
  83. local args = {
  84. [1] = {
  85. [1] = {
  86. ["\3"] = "vote",
  87. ["vote"] = true
  88. },
  89. [2] = "."
  90. }
  91. }
  92.  
  93. game:GetService("RunService").Heartbeat:Connect(function()
  94. stayOnTopOfNPC()
  95. if noclipEnabled and Character and Character.Humanoid then
  96. Character.Humanoid:ChangeState(11)
  97. end
  98.  
  99. local currentTime = tick()
  100. if currentTime - lastTeleportTime >= delay then
  101. lastTeleportTime = currentTime
  102. targetNPC = findNearestNPC()
  103.  
  104. if targetNPC then -- Check if a mob was found
  105. lastMobCheckTime = currentTime -- Reset timer if mob found
  106. -- Fire remote events
  107. if retryVote and retryVote.Enabled then
  108. dataRemoteEvent:FireServer(unpack(args))
  109. end
  110. if revivePrompt and revivePrompt.Enabled then
  111. print("RevivePrompt is enabled. Add your revive logic here.")
  112. end
  113. elseif currentTime - lastMobCheckTime >= noMobWaitTime then
  114. print("No mobs found. Waiting...")
  115. lastMobCheckTime = currentTime -- Keep waiting until a mob is found
  116. end
  117. end
  118. end)
  119.  
  120. -- Initialize
  121. targetNPC = findNearestNPC()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement