Advertisement
m9aari

Script stuff da strike

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