Advertisement
aesnike

scrtp Dungeon quest

Oct 17th, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local player = Players.LocalPlayer
  3. local character = player.Character or player.CharacterAdded:Wait()
  4. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  5. local humanoid = character:WaitForChild("Humanoid")
  6. local debounce = false
  7.  
  8. local forcefieldRange = 20 -- 10 studs range for the forcefield
  9. local baseForceMagnitude = 200 -- Force to push player away from danger
  10. local debounceTime = 0.1 -- Time delay to prevent rapid dodging
  11.  
  12. -- Function to apply a force that pushes the player away from dangerous objects
  13. local function applyForcefield(dangerousObject)
  14. local direction = (humanoidRootPart.Position - dangerousObject.Position).Unit
  15. local forceMagnitude = baseForceMagnitude
  16.  
  17. -- Apply force via BodyVelocity
  18. local bodyVelocity = Instance.new("BodyVelocity")
  19. bodyVelocity.Velocity = direction * forceMagnitude
  20. bodyVelocity.MaxForce = Vector3.new(100000, 0, 100000) -- Only X and Z axis force
  21. bodyVelocity.P = 1000
  22. bodyVelocity.Parent = humanoidRootPart
  23.  
  24. -- Remove the velocity effect after a short time
  25. game:GetService("Debris"):AddItem(bodyVelocity, 0.15)
  26. end
  27.  
  28. -- Function to continuously detect and dodge dangerous objects
  29. local function detectAndDodge()
  30. if debounce then return end
  31. debounce = true
  32.  
  33. -- Look for dangerous parts in the workspace
  34. for _, obj in pairs(workspace:GetDescendants()) do
  35. if obj:IsA("BasePart") and (obj.Name:lower():find("precast") or obj.Name:lower():find("hitbox")) then
  36. local distance = (humanoidRootPart.Position - obj.Position).Magnitude
  37.  
  38. -- If within range, apply the dodge effect
  39. if distance <= forcefieldRange then
  40. applyForcefield(obj)
  41. break -- Exit after dodging one object
  42. end
  43. end
  44. end
  45.  
  46. debounce = false
  47. task.wait(debounceTime)
  48. end
  49.  
  50. -- Function to reconnect the dodge mechanism when the player respawns
  51. local function onCharacterAdded(newCharacter)
  52. character = newCharacter
  53. humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  54. humanoid = character:WaitForChild("Humanoid")
  55.  
  56. -- Start detecting and dodging again after respawn
  57. while true do
  58. detectAndDodge()
  59. task.wait(0.05) -- Frequent checks for dangerous objects
  60. end
  61. end
  62.  
  63. -- Initial setup for the current character
  64. while true do
  65. detectAndDodge() -- Start detecting and dodging dangerous objects
  66. task.wait(0.05) -- Frequent checks
  67. end
  68.  
  69. -- Reapply the dodge logic when the player respawns
  70. player.CharacterAdded:Connect(onCharacterAdded)
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement