Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local RunService = game:GetService("RunService")
- -- Variables
- local tpActive = false
- local tpLoop = nil
- local Character = LocalPlayer.Character
- local targetNPC = nil
- local offset = Vector3.new(0, 9, 0) -- Fixed offset above enemy
- -- GUI Setup
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Name = "TeleportGUI"
- ScreenGui.ResetOnSpawn = false
- ScreenGui.Parent = game.CoreGui
- local Button = Instance.new("TextButton")
- Button.Name = "TeleportButton"
- Button.Size = UDim2.new(0, 100, 0, 50)
- Button.Position = UDim2.new(1, -110, 0.5, -25)
- Button.AnchorPoint = Vector2.new(1, 0.5)
- Button.BackgroundColor3 = Color3.new(0, 0, 0)
- Button.TextColor3 = Color3.new(1, 1, 1)
- Button.Text = "TP: OFF"
- Button.Font = Enum.Font.SourceSansBold
- Button.TextSize = 18
- Button.Parent = ScreenGui
- Button.ZIndex = 9999
- Button.AutoButtonColor = true
- -- Save/Load Functions
- local function saveToWorkspace()
- if not workspace:FindFirstChild("TeleportData") then
- local saveValue = Instance.new("BoolValue")
- saveValue.Name = "TeleportData"
- saveValue.Value = tpActive
- saveValue.Parent = workspace
- else
- workspace.TeleportData.Value = tpActive
- end
- end
- local function loadFromWorkspace()
- if workspace:FindFirstChild("TeleportData") then
- return workspace.TeleportData.Value
- end
- return false
- end
- -- Teleport Functions
- local function freezeCharacter()
- if Character and Character:FindFirstChild('Humanoid') then
- Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
- end
- end
- local function unfreezeCharacter()
- if Character and Character:FindFirstChild('Humanoid') then
- Character.Humanoid:ChangeState(Enum.HumanoidStateType.Running)
- end
- end
- local function findNearestNPC()
- local nearestNPC = nil
- local nearestDistance = math.huge
- Character = LocalPlayer.Character
- if not Character or not Character:FindFirstChild("HumanoidRootPart") then return end
- for _, folder in ipairs(workspace:GetChildren()) do
- if folder:IsA("Folder") then
- for _, child in ipairs(folder:GetChildren()) do
- if child:FindFirstChild("enemyFolder") then
- for _, npc in ipairs(child.enemyFolder:GetChildren()) do
- if npc:FindFirstChild("HumanoidRootPart") and
- npc:FindFirstChild("Humanoid") and
- npc.Humanoid.Health > 0 then
- local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
- if distance < nearestDistance then
- nearestDistance = distance
- nearestNPC = npc
- end
- end
- end
- end
- end
- end
- end
- return nearestNPC
- end
- local function stayOnTopOfTarget()
- if not targetNPC or not targetNPC.Parent or not targetNPC:FindFirstChild("HumanoidRootPart") then
- targetNPC = findNearestNPC()
- if not targetNPC then
- wait(0.1) -- Short wait if no targets found
- return
- end
- end
- if Character and Character:FindFirstChild("HumanoidRootPart") and
- targetNPC and targetNPC:FindFirstChild("HumanoidRootPart") then
- -- Calculate fixed position above enemy
- local targetPos = targetNPC.HumanoidRootPart.Position + offset
- local targetCFrame = CFrame.new(targetPos, targetNPC.HumanoidRootPart.Position)
- -- Smooth lerp to target position
- Character.HumanoidRootPart.CFrame = Character.HumanoidRootPart.CFrame:Lerp(targetCFrame, 0.5)
- end
- end
- local function toggleTP(isEnabled)
- tpActive = isEnabled
- if isEnabled then
- freezeCharacter()
- if not tpLoop then
- tpLoop = RunService.Heartbeat:Connect(function()
- if tpActive then
- stayOnTopOfTarget()
- end
- end)
- end
- Button.BackgroundColor3 = Color3.new(0, 1, 0)
- Button.TextColor3 = Color3.new(0, 0, 0)
- Button.Text = "TP: ON"
- else
- if tpLoop then
- tpLoop:Disconnect()
- tpLoop = nil
- end
- unfreezeCharacter()
- Button.BackgroundColor3 = Color3.new(1, 0, 0)
- Button.TextColor3 = Color3.new(1, 1, 1)
- Button.Text = "TP: OFF"
- end
- saveToWorkspace()
- end
- -- Button Click Handler
- Button.MouseButton1Click:Connect(function()
- toggleTP(not tpActive)
- end)
- -- Character Added Function
- local function onCharacterAdded(newCharacter)
- Character = newCharacter
- wait(1)
- if tpActive then
- toggleTP(true)
- end
- end
- -- Initialize
- LocalPlayer.CharacterAdded:Connect(onCharacterAdded)
- if LocalPlayer.Character then
- onCharacterAdded(LocalPlayer.Character)
- end
- -- Load saved state
- tpActive = loadFromWorkspace()
- if tpActive then
- toggleTP(true)
- end
- -- Cleanup
- game:BindToClose(function()
- if tpLoop then
- tpLoop:Disconnect()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement