Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax-m1· MiniMaxHugging Face LMArena Human Preference 140K

eok i like the animation but i want it to be in the middle of the screen for all devises…

  1. User

    eok i like the animation but i want it to be in the middle of the screen for all devises also i dont want you to step over it i want you to like press or touch the button then gets teleported to the part thats named something

  2. MiniMax Assistant

    Got it! I'll modify the script to center the UI perfectly on all devices and teleport to a part by name. Here's the updated script with clear instructions:

    -- Centered Loading Animation + Teleport to Named Part
    -- Copy/paste this into a Script inside your button part
    
    local button = script.Parent
    local TweenService = game:GetService("TweenService")
    local Players = game:GetService("Players")
    
    -- ==== CONFIGURATION ==== --
    local teleportTargetName = "NextRoomPart" -- Name of the part to teleport to
    local loadingTime = 2 -- Seconds to show loading screen
    -- ======================== --
    
    -- Create UI elements
    local function createLoadingUI(player)
        local playerGui = player:WaitForChild("PlayerGui")
        local screenGui = Instance.new("ScreenGui")
        screenGui.Name = "LoadingScreen"
        screenGui.Parent = playerGui
        
        -- Black background
        local blackFrame = Instance.new("Frame")
        blackFrame.Name = "BlackFrame"
        blackFrame.Size = UDim2.new(1, 0, 1, 0) -- Full screen
        blackFrame.Position = UDim2.new(0, 0, -1, 0) -- Start above screen
        blackFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
        blackFrame.BorderSizePixel = 0
        blackFrame.Parent = screenGui
        
        -- Centered loading text
        local loadingText = Instance.new("TextLabel")
        loadingText.Name = "LoadingText"
        loadingText.Size = UDim2.new(0, 300, 0, 100) -- Fixed size for centering
        loadingText.Position = UDim2.new(0.5, -150, 0.5, -50) -- Perfect center
        loadingText.BackgroundTransparency = 1
        loadingText.Text = "Loading."
        loadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
        loadingText.TextScaled = true
        loadingText.Font = Enum.Font.SourceSansBold
        loadingText.Parent = blackFrame
        
        return blackFrame, loadingText, screenGui
    end
    
    -- Handle teleportation
    local function handleTeleport(player)
        local targetPart = workspace:FindFirstChild(teleportTargetName)
        
        if not targetPart then
            warn("⚠️ Target part '"..teleportTargetName.."' not found in Workspace!")
            return
        end
        
        if not targetPart:IsA("BasePart") then
            warn("⚠️ '"..teleportTargetName.."' is not a BasePart (like a Part/Cube)")
            return
        end
        
        local character = player.Character
        if character and character:FindFirstChild("HumanoidRootPart") then
            character.HumanoidRootPart.CFrame = targetPart.CFrame
        end
    end
    
    -- Animation sequence
    local function showLoadingAnimation(player)
        local blackFrame, loadingText, screenGui = createLoadingUI(player)
        
        -- Slide in animation
        local slideIn = TweenService:Create(
            blackFrame,
            TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
            {Position = UDim2.new(0, 0, 0, 0)}
        )
        slideIn:Play()
        
        -- Bouncing dots animation
        local dotPhase = 1
        local isAnimating = true
        spawn(function()
            while isAnimating do
                loadingText.Text = "Loading"..string.rep(".", dotPhase)
                dotPhase = (dotPhase % 3) + 1
                wait(0.5)
            end
        end)
        
        -- Wait and teleport
        wait(loadingTime)
        isAnimating = false
        handleTeleport(player)
        
        -- Slide out animation
        local slideOut = TweenService:Create(
            blackFrame,
            TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
            {Position = UDim2.new(0, 0, 1, 0)}
        )
        slideOut:Play()
        slideOut.Completed:Connect(function()
            screenGui:Destroy()
        end)
    end
    
    -- Both touch and click detection
    button.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then showLoadingAnimation(player) end
    end)
    
    local clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = button
    clickDetector.MouseClick:Connect(function(player)
        showLoadingAnimation(player)
    end)
    

    How to Set Up:

    1. Create Your Button:

      • Make any part in Workspace (like a cube or sphere)
      • Name it whatever you want (doesn't matter)
      • Insert this script into the button part
    2. Create Target Part:

      • In Workspace, create a part where you want players to teleport
      • Name it exactly NextRoomPart (case-sensitive!)
      • Position it where you want players to go
    3. Test It:

      • Press Play in Studio
      • Touch/click the button
      • You should see:
        • Black screen slides down from top
        • "Loading" with bouncing dots in center
        • Teleport to NextRoomPart after 2 seconds
        • Screen slides away

    Customization Options:

    • Change Teleport Target:
      Edit teleportTargetName = "NextRoomPart" to match your target part's name

    • Change Loading Time:
      Modify loadingTime = 2 (in seconds)

    • Change Animation Speed:
      Adjust the 0.5 values in the TweenInfo lines (lower = faster)

    • Change Text Color:
      Modify TextColor3 = Color3.fromRGB(255, 255, 255) (white) to any RGB color

    Common Issues Fixed:

    • UI Not Centered?
      The Position = UDim2.new(0.5, -150, 0.5, -50) centers the text perfectly. The numbers are half the text's width/height.

    • Teleport Not Working?
      Ensure:

      1. Target part exists in Workspace
      2. Target part is named exactly as in the script
      3. Target part is a BasePart (like a Part, not a Decal or Sound)
    • Animation Too Fast/Slow?
      Adjust the 0.5 in TweenInfo.new(0.5, ...) and wait(0.5) lines.

    This script handles both touch and click inputs and works on all devices! Let me know if you need help creating the target part or have any other questions. 😊