Advertisement
aesnike

DODGE(UPD)

Oct 30th, 2024 (edited)
78
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. -- Configuration
  5. local DETECTION_RADIUS = 15
  6. local CHECK_INTERVAL = 0.1
  7. local SAFE_DISTANCE = 10
  8. local PRIORITY_LEVEL = Enum.RenderPriority.Last.Value
  9.  
  10. -- Initialize core variables
  11. local player = Players.LocalPlayer
  12. local character = player.Character or player.CharacterAdded:Wait()
  13. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  14. local debounce = false
  15. local isOverriding = false
  16.  
  17. -- Helper function to safely find character parts
  18. local function getCharacterParts()
  19. local char = player.Character
  20. if not char then return end
  21.  
  22. return {
  23. root = char:FindFirstChild("HumanoidRootPart"),
  24. humanoid = char:FindFirstChild("Humanoid")
  25. }
  26. end
  27.  
  28. -- Character state management functions
  29. local function freezeCharacter(character)
  30. if character and character:FindFirstChild("HumanoidRootPart") then
  31. character.HumanoidRootPart.Anchored = true
  32. end
  33. end
  34.  
  35. local function unfreezeCharacter(character)
  36. if character and character:FindFirstChild("HumanoidRootPart") then
  37. character.HumanoidRootPart.Anchored = false
  38. end
  39. end
  40.  
  41. -- Enhanced safe position finding
  42. local function findSafePosition(currentPos)
  43. local safePos = currentPos + Vector3.new(SAFE_DISTANCE, 0, SAFE_DISTANCE)
  44.  
  45. local ray = Ray.new(safePos + Vector3.new(0, 5, 0), Vector3.new(0, -10, 0))
  46. local hit, pos = workspace:FindPartOnRay(ray)
  47.  
  48. if hit then
  49. return pos + Vector3.new(0, 3, 0)
  50. end
  51.  
  52. return safePos
  53. end
  54.  
  55. -- Priority override teleport function
  56. local function priorityTeleport(position)
  57. local parts = getCharacterParts()
  58. if not parts.root or not parts.humanoid then return end
  59.  
  60. isOverriding = true
  61. freezeCharacter(player.Character) -- Freeze before teleporting
  62.  
  63. -- Disable other possible movement
  64. local originalWalkSpeed = parts.humanoid.WalkSpeed
  65. local originalJumpPower = parts.humanoid.JumpPower
  66. parts.humanoid.WalkSpeed = 0
  67. parts.humanoid.JumpPower = 0
  68.  
  69. -- Force position update on multiple frames
  70. local startTime = tick()
  71. local connection
  72. connection = RunService.RenderStepped:Connect(function()
  73. if tick() - startTime > 0.1 then -- Force for 0.1 seconds
  74. connection:Disconnect()
  75.  
  76. -- Restore original states
  77. unfreezeCharacter(player.Character)
  78. parts.humanoid.PlatformStand = false
  79. parts.humanoid.WalkSpeed = originalWalkSpeed
  80. parts.humanoid.JumpPower = originalJumpPower
  81. isOverriding = false
  82. return
  83. end
  84.  
  85. -- Aggressively maintain position
  86. if parts.root then
  87. parts.root.CFrame = CFrame.new(position)
  88. parts.root.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
  89. parts.root.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
  90. end
  91. end)
  92. end
  93.  
  94. -- Enhanced object detection
  95. local function detectDangerousObjects()
  96. local objectsFound = {}
  97. local parts = getCharacterParts()
  98. if not parts.root then return objectsFound end
  99.  
  100. local overlapParams = OverlapParams.new()
  101. overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
  102. overlapParams.FilterDescendantsInstances = {player.Character}
  103.  
  104. local nearbyParts = workspace:GetPartBoundsInRadius(
  105. parts.root.Position,
  106. DETECTION_RADIUS,
  107. overlapParams
  108. )
  109.  
  110. for _, part in ipairs(nearbyParts) do
  111. if part.Name == "precast" or part.Name == "hitbox" then
  112. table.insert(objectsFound, {
  113. part = part,
  114. distance = (parts.root.Position - part.Position).Magnitude
  115. })
  116. end
  117. end
  118.  
  119. -- Sort by distance for priority handling
  120. table.sort(objectsFound, function(a, b)
  121. return a.distance < b.distance
  122. end)
  123.  
  124. return objectsFound
  125. end
  126.  
  127. -- Priority detection loop
  128. local function startPriorityLoop()
  129. RunService:BindToRenderStep(
  130. "DodgePriorityLoop",
  131. PRIORITY_LEVEL,
  132. function()
  133. if debounce or isOverriding then return end
  134.  
  135. local parts = getCharacterParts()
  136. if not parts.root then return end
  137.  
  138. local dangerousObjects = detectDangerousObjects()
  139.  
  140. if #dangerousObjects > 0 then
  141. for _, obj in ipairs(dangerousObjects) do
  142. if obj.distance <= DETECTION_RADIUS then
  143. debounce = true
  144.  
  145. local safePos = findSafePosition(parts.root.Position)
  146. priorityTeleport(safePos)
  147.  
  148. task.spawn(function()
  149. task.wait(CHECK_INTERVAL)
  150. debounce = false
  151. end)
  152. break
  153. end
  154. end
  155. else
  156. -- No dangerous objects detected, ensure character is unfrozen
  157. unfreezeCharacter(player.Character)
  158. end
  159. end
  160. )
  161. end
  162.  
  163. -- Enhanced respawn handling
  164. local function cleanupOldCharacter()
  165. if character then
  166. -- Cleanup any existing override states
  167. unfreezeCharacter(character)
  168. local parts = getCharacterParts()
  169. if parts.humanoid then
  170. parts.humanoid.PlatformStand = false
  171. end
  172. end
  173. end
  174.  
  175. local function handleRespawn(newCharacter)
  176. cleanupOldCharacter()
  177. character = newCharacter
  178. humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  179.  
  180. -- Reset states
  181. debounce = false
  182. isOverriding = false
  183.  
  184. -- Restart priority loop
  185. RunService:UnbindFromRenderStep("DodgePriorityLoop")
  186. startPriorityLoop()
  187. end
  188.  
  189. -- Initialize
  190. player.CharacterAdded:Connect(handleRespawn)
  191. startPriorityLoop()
  192.  
  193. -- Cleanup on script end
  194. game:BindToClose(function()
  195. RunService:UnbindFromRenderStep("DodgePriorityLoop")
  196. cleanupOldCharacter()
  197. end)
Advertisement
Comments
  • Epiclo12
    257 days
    # text 0.11 KB | 0 0
    1. can you add me on discorD? im trying to make a dungeon quest autofarm as well and have a goood start
    2.  
    3. @maybachlump
Add Comment
Please, Sign In to add comment
Advertisement