lua Copy code
-- Click-only Loading Animation with Bouncing Dots
-- 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 part to teleport to
local loadingTime = 2 -- Seconds to show loading screen
local isClickable = true -- Track if button is clickable
-- 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)
blackFrame.Position = UDim2.new(0, 0, -1, 0)
blackFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
blackFrame.BorderSizePixel = 0
blackFrame.Parent = screenGui
-- Centered loading text container
local loadingContainer = Instance.new("Frame")
loadingContainer.Size = UDim2.new(0, 300, 0, 100)
loadingContainer.Position = UDim2.new(0.5, -150, 0.5, -50)
loadingContainer.BackgroundTransparency = 1
loadingContainer.Parent = blackFrame
-- Loading text
local loadingText = Instance.new("TextLabel")
loadingText.Size = UDim2.new(1, 0, 0.7, 0)
loadingText.Position = UDim2.new(0, 0, 0, 0)
loadingText.BackgroundTransparency = 1
loadingText.Text = "Loading"
loadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
loadingText.TextScaled = true
loadingText.Font = Enum.Font.SourceSansBold
loadingText.Parent = loadingContainer
-- Bouncing dots
local dots = Instance.new("TextLabel")
dots.Size = UDim2.new(1, 0, 0.3, 0)
dots.Position = UDim2.new(0, 0, 0.7, 0)
dots.BackgroundTransparency = 1
dots.Text = "."
dots.TextColor3 = Color3.fromRGB(255, 255, 255)
dots.TextScaled = true
dots.Font = Enum.Font.SourceSansBold
dots.Parent = loadingContainer
return blackFrame, loadingText, dots, screenGui
end
-- Handle teleportation
local function handleTeleport(player)
local targetPart = workspace:FindFirstChild(teleportTargetName)
if targetPart and targetPart:IsA("BasePart") then
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
character.HumanoidRootPart.CFrame = targetPart.CFrame
end
else
warn("Target part not found or not a BasePart")
end
end
-- Animation sequence
local function showLoadingAnimation(player)
local blackFrame, loadingText, dots, 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 dotCount = 1
local isAnimating = true
spawn(function()
while isAnimating do
dots.Text = string.rep(".", dotCount)
dotCount = (dotCount % 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()
isClickable = true
end)
end
-- Click detection
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = button
clickDetector.MouseClick:Connect(function(player)
if isClickable then
isClickable = false
showLoadingAnimation(player)
end
end)
This should now work as expected on all devices! Let me know if you need further adjustments.