Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- -- Configuration
- local DETECTION_RADIUS = 15
- local CHECK_INTERVAL = 0.1
- local SAFE_DISTANCE = 10
- local PRIORITY_LEVEL = Enum.RenderPriority.Last.Value
- -- Initialize core variables
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- local debounce = false
- local isOverriding = false
- -- Helper function to safely find character parts
- local function getCharacterParts()
- local char = player.Character
- if not char then return end
- return {
- root = char:FindFirstChild("HumanoidRootPart"),
- humanoid = char:FindFirstChild("Humanoid")
- }
- end
- -- Character state management functions
- local function freezeCharacter(character)
- if character and character:FindFirstChild("HumanoidRootPart") then
- character.HumanoidRootPart.Anchored = true
- end
- end
- local function unfreezeCharacter(character)
- if character and character:FindFirstChild("HumanoidRootPart") then
- character.HumanoidRootPart.Anchored = false
- end
- end
- -- Enhanced safe position finding
- local function findSafePosition(currentPos)
- local safePos = currentPos + Vector3.new(SAFE_DISTANCE, 0, SAFE_DISTANCE)
- local ray = Ray.new(safePos + Vector3.new(0, 5, 0), Vector3.new(0, -10, 0))
- local hit, pos = workspace:FindPartOnRay(ray)
- if hit then
- return pos + Vector3.new(0, 3, 0)
- end
- return safePos
- end
- -- Priority override teleport function
- local function priorityTeleport(position)
- local parts = getCharacterParts()
- if not parts.root or not parts.humanoid then return end
- isOverriding = true
- freezeCharacter(player.Character) -- Freeze before teleporting
- -- Disable other possible movement
- local originalWalkSpeed = parts.humanoid.WalkSpeed
- local originalJumpPower = parts.humanoid.JumpPower
- parts.humanoid.WalkSpeed = 0
- parts.humanoid.JumpPower = 0
- -- Force position update on multiple frames
- local startTime = tick()
- local connection
- connection = RunService.RenderStepped:Connect(function()
- if tick() - startTime > 0.1 then -- Force for 0.1 seconds
- connection:Disconnect()
- -- Restore original states
- unfreezeCharacter(player.Character)
- parts.humanoid.PlatformStand = false
- parts.humanoid.WalkSpeed = originalWalkSpeed
- parts.humanoid.JumpPower = originalJumpPower
- isOverriding = false
- return
- end
- -- Aggressively maintain position
- if parts.root then
- parts.root.CFrame = CFrame.new(position)
- parts.root.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
- parts.root.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
- end
- end)
- end
- -- Enhanced object detection
- local function detectDangerousObjects()
- local objectsFound = {}
- local parts = getCharacterParts()
- if not parts.root then return objectsFound end
- local overlapParams = OverlapParams.new()
- overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
- overlapParams.FilterDescendantsInstances = {player.Character}
- local nearbyParts = workspace:GetPartBoundsInRadius(
- parts.root.Position,
- DETECTION_RADIUS,
- overlapParams
- )
- for _, part in ipairs(nearbyParts) do
- if part.Name == "precast" or part.Name == "hitbox" then
- table.insert(objectsFound, {
- part = part,
- distance = (parts.root.Position - part.Position).Magnitude
- })
- end
- end
- -- Sort by distance for priority handling
- table.sort(objectsFound, function(a, b)
- return a.distance < b.distance
- end)
- return objectsFound
- end
- -- Priority detection loop
- local function startPriorityLoop()
- RunService:BindToRenderStep(
- "DodgePriorityLoop",
- PRIORITY_LEVEL,
- function()
- if debounce or isOverriding then return end
- local parts = getCharacterParts()
- if not parts.root then return end
- local dangerousObjects = detectDangerousObjects()
- if #dangerousObjects > 0 then
- for _, obj in ipairs(dangerousObjects) do
- if obj.distance <= DETECTION_RADIUS then
- debounce = true
- local safePos = findSafePosition(parts.root.Position)
- priorityTeleport(safePos)
- task.spawn(function()
- task.wait(CHECK_INTERVAL)
- debounce = false
- end)
- break
- end
- end
- else
- -- No dangerous objects detected, ensure character is unfrozen
- unfreezeCharacter(player.Character)
- end
- end
- )
- end
- -- Enhanced respawn handling
- local function cleanupOldCharacter()
- if character then
- -- Cleanup any existing override states
- unfreezeCharacter(character)
- local parts = getCharacterParts()
- if parts.humanoid then
- parts.humanoid.PlatformStand = false
- end
- end
- end
- local function handleRespawn(newCharacter)
- cleanupOldCharacter()
- character = newCharacter
- humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- -- Reset states
- debounce = false
- isOverriding = false
- -- Restart priority loop
- RunService:UnbindFromRenderStep("DodgePriorityLoop")
- startPriorityLoop()
- end
- -- Initialize
- player.CharacterAdded:Connect(handleRespawn)
- startPriorityLoop()
- -- Cleanup on script end
- game:BindToClose(function()
- RunService:UnbindFromRenderStep("DodgePriorityLoop")
- cleanupOldCharacter()
- end)
Advertisement
Comments
-
- can you add me on discorD? im trying to make a dungeon quest autofarm as well and have a goood start
- @maybachlump
Add Comment
Please, Sign In to add comment
Advertisement