Advertisement
m9aari

Da downhill auto shield

Nov 15th, 2024 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. -- Place this script in StarterPlayerScripts
  2.  
  3. local Players = game:GetService("Players")
  4. local player = Players.LocalPlayer
  5. local function initializeScript()
  6. local character = player.Character or player.CharacterAdded:Wait()
  7. local humanoid = character:WaitForChild("Humanoid")
  8. local lastHealth = humanoid.Health
  9. local originalPosition
  10. local isTeleporting = false -- Track if teleport is in progress to prevent repeated teleportation
  11. local cooldownTime = 2 -- Cooldown time in seconds to prevent immediate retriggers
  12. local unequippedTool = nil -- Store the unequipped tool
  13.  
  14. -- Function to teleport, unequip tool, interact with a ClickDetector, and re-equip tool
  15. local function teleportAndInteract()
  16. if isTeleporting then return end -- Prevent teleport if already in progress
  17. isTeleporting = true -- Set teleporting flag
  18.  
  19. -- Store the exact original position of HumanoidRootPart
  20. originalPosition = character.HumanoidRootPart.CFrame
  21.  
  22. -- Find the "MAP" folder in the workspace
  23. local map = workspace:FindFirstChild("MAP")
  24. if not map then
  25. warn("MAP folder not found in workspace.")
  26. isTeleporting = false
  27. return
  28. end
  29.  
  30. -- Find the "Pads" folder inside "MAP"
  31. local padsFolder = map:FindFirstChild("Shops")
  32. if not padsFolder then
  33. warn("Pads folder not found inside MAP.")
  34. isTeleporting = false
  35. return
  36. end
  37.  
  38. -- Collect all "[Medium Armor]" pads
  39. local mediumArmorPads = {}
  40. for _, pad in ipairs(padsFolder:GetChildren()) do
  41. if pad:IsA("Model") and pad.Name == "[High-Medium Armor]" then
  42. table.insert(mediumArmorPads, pad)
  43. end
  44. end
  45.  
  46. -- If no "[Medium Armor]" pads were found, exit
  47. if #mediumArmorPads == 0 then
  48. warn("No [Medium Armor] pads found in Pads folder.")
  49. isTeleporting = false
  50. return
  51. end
  52.  
  53. -- Choose a random pad
  54. local chosenPad = mediumArmorPads[math.random(1, #mediumArmorPads)]
  55. local clickDetector = chosenPad:FindFirstChild("ClickDetector")
  56. if not clickDetector then
  57. warn("ClickDetector not found in the chosen [Medium Armor] pad.")
  58. isTeleporting = false
  59. return
  60. end
  61.  
  62. -- Find the "Head" part inside the chosen [Medium Armor] model for teleportation
  63. local headPart = chosenPad:FindFirstChild("Head")
  64. if not headPart then
  65. warn("No 'Head' part found inside the chosen [Medium Armor] model.")
  66. isTeleporting = false
  67. return
  68. end
  69.  
  70. -- Temporarily anchor the character to ensure stable teleportation
  71. character.HumanoidRootPart.Anchored = true
  72.  
  73. -- Check for currently equipped tool and unequip it
  74. local currentTool = character:FindFirstChildOfClass("Tool")
  75. if currentTool then
  76. unequippedTool = currentTool -- Store the equipped tool
  77. currentTool.Parent = player.Backpack -- Move tool to backpack to unequip
  78. end
  79.  
  80. -- Teleport to the "Head" part of the chosen pad
  81. character.HumanoidRootPart.CFrame = headPart.CFrame
  82.  
  83. -- Interact with the ClickDetector (simulate click)
  84. fireclickdetector(clickDetector)
  85.  
  86. -- Wait briefly to ensure interaction completes
  87. wait(0.5)
  88.  
  89. -- Teleport back to the original position
  90. character.HumanoidRootPart.CFrame = originalPosition
  91.  
  92. -- Re-equip the tool if it was equipped before
  93. if unequippedTool then
  94. unequippedTool.Parent = character -- Move tool back to character to re-equip
  95. end
  96.  
  97. -- If no tool was equipped before teleporting, ensure nothing is equipped
  98. if not unequippedTool then
  99. local currentTool = character:FindFirstChildOfClass("Tool")
  100. if currentTool then
  101. currentTool.Parent = player.Backpack -- Move tool back to backpack if any was equipped
  102. end
  103. end
  104.  
  105. -- Unanchor the character
  106. wait(0.2)
  107. character.HumanoidRootPart.Anchored = false
  108.  
  109. -- End teleportation and start cooldown
  110. wait(cooldownTime)
  111. isTeleporting = false
  112. end
  113.  
  114. -- Monitor health changes
  115. local function onHealthChanged(newHealth)
  116. -- Trigger teleportation only once per health drop and check cooldown
  117. if newHealth < lastHealth and not isTeleporting then
  118. teleportAndInteract()
  119. end
  120. lastHealth = newHealth -- Update last health value
  121. end
  122.  
  123. -- Connect the health change event
  124. humanoid.HealthChanged:Connect(onHealthChanged)
  125. end
  126.  
  127. -- Ensure the script reattaches to the new character upon respawn
  128. player.CharacterAdded:Connect(function()
  129. initializeScript()
  130. end)
  131.  
  132. -- Initialize script when the player first joins
  133. initializeScript()
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement