Advertisement
aesnike

scrtp Dungeon quest

Oct 17th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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 = 10 -- 10 studs range for the forcefield
  9. local forceMagnitude = 50 -- The amount of force applied to push the player away
  10.  
  11. -- Function to apply a forcefield effect
  12. local function applyForcefield(object)
  13. -- Calculate direction away from the object, ignoring the Y axis (for horizontal movement)
  14. local horizontalDirection = (humanoidRootPart.Position - object.Position)
  15. horizontalDirection = Vector3.new(horizontalDirection.X, 0, horizontalDirection.Z).Unit -- Flatten Y-axis movement
  16.  
  17. local force = horizontalDirection * forceMagnitude -- Apply force in the horizontal direction
  18. humanoidRootPart.Velocity = humanoidRootPart.Velocity + force -- Adjust the player's velocity
  19. end
  20.  
  21. -- Function to check for dangerous objects within forcefield range
  22. local function checkForcefield()
  23. if debounce then return end
  24. debounce = true
  25.  
  26. local dangerousObjects = {}
  27.  
  28. -- Recursively find all dangerous objects in the workspace
  29. local function findDangerousObjects(parent)
  30. for _, child in pairs(parent:GetChildren()) do
  31. if child:IsA("BasePart") and (child.Name == "precast" or child.Name == "hitbox") then
  32. table.insert(dangerousObjects, child)
  33. end
  34. findDangerousObjects(child) -- Recursive call to check child objects
  35. end
  36. end
  37.  
  38. findDangerousObjects(workspace)
  39.  
  40. -- Check proximity to each dangerous object and apply the forcefield if within range
  41. for _, obj in pairs(dangerousObjects) do
  42. if obj and obj:IsA("BasePart") then
  43. local distance = (humanoidRootPart.Position - obj.Position).Magnitude
  44.  
  45. -- If within the 10-stud forcefield range, apply the forcefield effect
  46. if distance <= forcefieldRange then
  47. applyForcefield(obj)
  48. break -- Exit after applying forcefield to one object
  49. end
  50. end
  51. end
  52.  
  53. debounce = false
  54. task.wait() -- Pause to prevent spamming the function
  55. end
  56.  
  57. -- Initial setup for the current character
  58. while true do
  59. checkForcefield()
  60. end
  61.  
Tags: scry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement