lua Copy code
-- Complete Button Script with Bouncing Dots and Teleportation
-- Place this script INSIDE your button part (e.g., named "TeleportButton")
local button = script.Parent
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
-- CONFIGURE THESE:
local teleportTargetName = "NextRoomPart" -- EXACT name of the part in the next room
local loadingTime = 2 -- Seconds for loading animation
local isClickable = true -- Prevent multiple clicks
-- 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) -- Start above screen
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, 120)
loadingContainer.Position = UDim2.new(0.5, -150, 0.5, -60)
loadingContainer.BackgroundTransparency = 1
loadingContainer.Parent = blackFrame
-- Loading text
local loadingText = Instance.new("TextLabel")
loadingText.Size = UDim2.new(1, 0, 0.6, 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
-- Dots container
local dotsContainer = Instance.new("Frame")
dotsContainer.Size = UDim2.new(0, 60, 0, 30)
dotsContainer.Position = UDim2.new(0.5, -30, 0.7, 0)
dotsContainer.BackgroundTransparency = 1
dotsContainer.Parent = loadingContainer
-- Create three dots
local dotLabels = {}
for i = 1, 3 do
local dot = Instance.new("TextLabel")
dot.Size = UDim2.new(0, 20, 0, 30)
dot.Position = UDim2.new((i-1)/3, 0, 0, 0)
dot.BackgroundTransparency = 1
dot.Text = "."
dot.TextColor3 = Color3.fromRGB(255, 255, 255)
dot.TextScaled = true
dot.Font = Enum.Font.SourceSansBold
dot.Parent = dotsContainer
table.insert(dotLabels, dot)
end
return blackFrame, dotLabels, 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 + Vector3.new(0, 3, 0) -- Teleport 3 studs above
print("Teleported to " .. teleportTargetName)
end
else
warn("⚠️ " .. teleportTargetName .. " not found in Workspace!")
end
end
-- Show loading animation
local function showLoadingAnimation(player)
local blackFrame, dotLabels, 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 wave animation
local isAnimating = true
spawn(function()
local t = 0
while isAnimating do
t = t + 0.1
for i, dot in ipairs(dotLabels) do
-- Wave motion: each dot is offset in phase
local offset = math.sin(t * math.pi * 2 + (i-1) * math.pi/3) * 8 -- 8 pixels up/down
dot.Position = UDim2.new((i-1)/3, 0, 0, offset)
end
wait(0.05)
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
-- Create click detector (NOT touch)
local clickDetector = Instance.new("ClickDetector")
clickDetector.MaxActivationDistance = 10 -- Click range
clickDetector.Parent = button
-- Handle clicks only
clickDetector.MouseClick:Connect(function(player)
if isClickable then
isClickable = false
print(player.Name .. " clicked the button!")
showLoadingAnimation(player)
end
end)
-- Optional: Make button visually clickable
button.Material = Enum.Material.Neon
button.BrickColor = BrickColor.new("Bright red")