Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Full script for the Auto Shield functionality with teleportation and health monitoring
- -- Place this script in StarterPlayerScripts
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local function initializeScript()
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local lastHealth = humanoid.Health
- local originalPosition
- local isTeleporting = false -- Track if teleport is in progress to prevent repeated teleportation
- local cooldownTime = 2 -- Cooldown time in seconds to prevent immediate retriggers
- local unequippedTool = nil -- Store the unequipped tool
- -- Function to teleport, unequip tool, interact with a ClickDetector, and re-equip tool
- local function teleportAndInteract()
- if isTeleporting then return end -- Prevent teleport if already in progress
- isTeleporting = true -- Set teleporting flag
- -- Store the exact original position of HumanoidRootPart
- originalPosition = character.HumanoidRootPart.CFrame
- -- Find the "MAP" folder in the workspace
- local map = workspace:FindFirstChild("MAP")
- if not map then
- warn("MAP folder not found in workspace.")
- isTeleporting = false
- return
- end
- -- Find the "Pads" folder inside "MAP"
- local padsFolder = map:FindFirstChild("Pads")
- if not padsFolder then
- warn("Pads folder not found inside MAP.")
- isTeleporting = false
- return
- end
- -- Collect all "[Medium Armor]" pads
- local mediumArmorPads = {}
- for _, pad in ipairs(padsFolder:GetChildren()) do
- if pad:IsA("Model") and pad.Name == "[Medium Armor]" then
- table.insert(mediumArmorPads, pad)
- end
- end
- -- If no "[Medium Armor]" pads were found, exit
- if #mediumArmorPads == 0 then
- warn("No [Medium Armor] pads found in Pads folder.")
- isTeleporting = false
- return
- end
- -- Choose a random pad
- local chosenPad = mediumArmorPads[math.random(1, #mediumArmorPads)]
- local clickDetector = chosenPad:FindFirstChild("ClickDetector")
- if not clickDetector then
- warn("ClickDetector not found in the chosen [Medium Armor] pad.")
- isTeleporting = false
- return
- end
- -- Find the "Head" part inside the chosen [Medium Armor] model for teleportation
- local headPart = chosenPad:FindFirstChild("Head")
- if not headPart then
- warn("No 'Head' part found inside the chosen [Medium Armor] model.")
- isTeleporting = false
- return
- end
- -- Temporarily anchor the character to ensure stable teleportation
- character.HumanoidRootPart.Anchored = true
- -- Check for currently equipped tool and unequip it
- local currentTool = character:FindFirstChildOfClass("Tool")
- if currentTool then
- unequippedTool = currentTool -- Store the equipped tool
- currentTool.Parent = player.Backpack -- Move tool to backpack to unequip
- end
- -- Teleport to the "Head" part of the chosen pad
- character.HumanoidRootPart.CFrame = headPart.CFrame
- -- Interact with the ClickDetector (simulate click)
- fireclickdetector(clickDetector)
- -- Wait briefly to ensure interaction completes
- wait(0.5)
- -- Teleport back to the original position
- character.HumanoidRootPart.CFrame = originalPosition
- -- Re-equip the tool if it was equipped before
- if unequippedTool then
- unequippedTool.Parent = character -- Move tool back to character to re-equip
- end
- -- If no tool was equipped before teleporting, ensure nothing is equipped
- if not unequippedTool then
- local currentTool = character:FindFirstChildOfClass("Tool")
- if currentTool then
- currentTool.Parent = player.Backpack -- Move tool back to backpack if any was equipped
- end
- end
- -- Unanchor the character
- wait(0.2)
- character.HumanoidRootPart.Anchored = false
- -- End teleportation and start cooldown
- wait(cooldownTime)
- isTeleporting = false
- end
- -- Monitor health changes
- local function onHealthChanged(newHealth)
- -- Trigger teleportation only once per health drop and check cooldown
- if newHealth < lastHealth and not isTeleporting then
- teleportAndInteract()
- end
- lastHealth = newHealth -- Update last health value
- end
- -- Connect the health change event
- humanoid.HealthChanged:Connect(onHealthChanged)
- end
- -- Ensure the script reattaches to the new character upon respawn
- player.CharacterAdded:Connect(function()
- initializeScript()
- end)
- -- Initialize script when the player first joins
- initializeScript()
- -- Auto Shield functionality (place this in a separate function or alongside existing code)
- local function enableAutoShield()
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- if autoShieldEnabled then
- -- Simulate activating shield when health is low
- if humanoid.Health < humanoid.MaxHealth * 0.3 then
- -- Activate shield (this is a placeholder, you need actual shield logic)
- print("Auto Shield Activated!")
- end
- end
- end
- -- Run the Auto Shield check periodically
- while wait(1) do
- enableAutoShield()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement