-- LocalScript

local player = game.Players.LocalPlayer

local function getCharacter()
    return player.Character or player.CharacterAdded:Wait()
end

local character = getCharacter()
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local originalCFrame = nil
local floating = false
local bodyPos = nil

-- GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "NaNTeleportGUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")

local frame = Instance.new("Frame")
frame.Size = UDim2.new(0, 220, 0, 145)
frame.Position = UDim2.new(0.5, -110, 0.5, -72)
frame.BackgroundColor3 = Color3.fromRGB(15,15,15)
frame.BackgroundTransparency = 0.2
frame.BorderSizePixel = 0
frame.Active = true
frame.Draggable = true
frame.Parent = screenGui

local title = Instance.new("TextLabel")
title.Size = UDim2.new(1,0,0,25)
title.BackgroundTransparency = 1
title.Text = "NaN Teleport"
title.TextColor3 = Color3.new(1,1,1)
title.TextScaled = true
title.Font = Enum.Font.SourceSansBold
title.Parent = frame

-- Teleport Button
local teleportButton = Instance.new("TextButton")
teleportButton.Size = UDim2.new(0,180,0,45)
teleportButton.Position = UDim2.new(0.5,-90,0,35)
teleportButton.Text = "Teleport"
teleportButton.TextScaled = true
teleportButton.Font = Enum.Font.SourceSansBold
teleportButton.TextColor3 = Color3.new(1,1,1)
teleportButton.BackgroundColor3 = Color3.fromRGB(0,170,255)
teleportButton.BorderSizePixel = 0
teleportButton.Parent = frame

-- Return Button
local returnButton = Instance.new("TextButton")
returnButton.Size = UDim2.new(0,180,0,35)
returnButton.Position = UDim2.new(0.5,-90,0,90)
returnButton.Text = "Original Pos"
returnButton.TextScaled = true
returnButton.Font = Enum.Font.SourceSansBold
returnButton.TextColor3 = Color3.new(1,1,1)
returnButton.BackgroundColor3 = Color3.fromRGB(50,200,50)
returnButton.BorderSizePixel = 0
returnButton.Parent = frame

local function teleportFar()
    character = getCharacter()
    hrp = character:WaitForChild("HumanoidRootPart")
    humanoid = character:WaitForChild("Humanoid")

    originalCFrame = hrp.CFrame

    floating = true

    local hugePos = Vector3.new(9e18, 9e18, 9e18)

    hrp.CFrame = CFrame.new(hugePos)

    humanoid.PlatformStand = true

    if bodyPos then
        bodyPos:Destroy()
    end

    bodyPos = Instance.new("BodyPosition")
    bodyPos.Name = "FloatHold"
    bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    bodyPos.P = 1000000
    bodyPos.D = 1000
    bodyPos.Position = hugePos
    bodyPos.Parent = hrp

    task.spawn(function()
        while floating and hrp and hrp.Parent and bodyPos do
            bodyPos.Position = hugePos
            hrp.Velocity = Vector3.zero
            hrp.RotVelocity = Vector3.zero
            task.wait()
        end
    end)
end

local function returnToOriginal()
    if originalCFrame and hrp then
        floating = false

        if bodyPos then
            bodyPos:Destroy()
            bodyPos = nil
        end

        humanoid.PlatformStand = false
        hrp.CFrame = originalCFrame
    end
end

teleportButton.MouseButton1Click:Connect(function()
    teleportFar()
end)

returnButton.MouseButton1Click:Connect(function()
    returnToOriginal()
end)

-- Update character references after respawn
player.CharacterAdded:Connect(function(char)
    character = char
    hrp = character:WaitForChild("HumanoidRootPart")
    humanoid = character:WaitForChild("Humanoid")
end)
