Got it! Let's create a complete room system where each room has its own button that teleports to the next room. Here's how to set it up:
Step 1: Create the Rooms
- In Workspace, create two parts named:
Room1 (first room)
Room2 (second room)
- Inside each room, add:
- A button part (name it
TeleportButton)
- A spawn point (name it
TeleportSpot)
Step 2: Insert This Script into Each Button
-- Teleport Button Script (Place inside ALL buttons)
local button = script.Parent
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
-- Configuration
local loadingTime = 2 -- Seconds to show loading screen
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 (full screen)
local blackFrame = Instance.new("Frame")
blackFrame.Size = UDim2.new(1, 0, 1, 0)
blackFrame.Position = UDim2.new(0, 0, -1, 0) -- Starts above screen
blackFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
blackFrame.BorderSizePixel = 0
blackFrame.Parent = screenGui
-- Loading text + bouncing dots (centered)
local loadingContainer = Instance.new("Frame")
loadingContainer.Size = UDim2.new(0, 300, 0, 120)
loadingContainer.Position = UDim2.new(0.5, -150, 0.5, -60) -- Perfect center
loadingContainer.BackgroundTransparency = 1
loadingContainer.Parent = blackFrame
-- "Loading" text
local loadingText = Instance.new("TextLabel")
loadingText.Size = UDim2.new(1, 0, 0.6, 0)
loadingText.Text = "Loading"
loadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
loadingText.Font = Enum.Font.SourceSansBold
loadingText.TextScaled = true
loadingText.BackgroundTransparency = 1
loadingText.Parent = loadingContainer
-- Three bouncing dots (wave motion)
local dots = {}
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.7, 0)
dot.Text = "."
dot.TextColor3 = Color3.fromRGB(255, 255, 255)
dot.Font = Enum.Font.SourceSansBold
dot.TextScaled = true
dot.BackgroundTransparency = 1
dot.Parent = loadingContainer
table.insert(dots, dot)
end
return blackFrame, dots, screenGui
end
-- Teleport to the next room
local function teleportPlayer(player)
local currentRoom = button:FindFirstAncestorOfClass("Model") or button.Parent
local nextRoomName = "Room" .. (tonumber(string.match(currentRoom.Name, "%d+")) + 1)
local nextRoom = workspace:FindFirstChild(nextRoomName)
if nextRoom then
local teleportSpot = nextRoom:FindFirstChild("TeleportSpot")
if teleportSpot then
player.Character:SetPrimaryPartCFrame(teleportSpot.CFrame * CFrame.new(0, 3, 0))
end
end
end
-- Loading animation
local function showLoadingAnimation(player)
local blackFrame, dots, screenGui = createLoadingUI(player)
-- Slide in animation
TweenService:Create(
blackFrame,
TweenInfo.new(0.5, Enum.EasingStyle.Quad),
{Position = UDim2.new(0, 0, 0, 0)}
):Play()
-- Bouncing dots wave effect
local isAnimating = true
spawn(function()
local time = 0
while isAnimating do
time += 0.1
for i, dot in ipairs(dots) do
local offset = math.sin(time * 5 + i) * 10 -- Wave motion
dot.Position = UDim2.new((i-1)/3, 0, 0.7, offset)
end
wait(0.05)
end
end)
-- Teleport after delay
wait(loadingTime)
isAnimating = false
teleportPlayer(player)
-- Slide out animation
TweenService:Create(
blackFrame,
TweenInfo.new(0.5, Enum.EasingStyle.Quad),
{Position = UDim2.new(0, 0, 1, 0)}
):Play()
-- Clean up
blackFrame.Destroying:Once(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)
Step 3: Set Up Rooms Correctly
-
Room Structure Example:
Workspace
├─ Room1
│ ├─ TeleportButton (with script inside)
│ └─ TeleportSpot (part where players spawn)
├─ Room2
│ ├─ TeleportButton (with script inside)
│ └─ TeleportSpot
├─ Room3
│ ├─ ...
-
Naming Rules:
- Rooms must be named
Room1, Room2, Room3, etc.
- Each room must have:
- A button named
TeleportButton (with the script inside).
- A spawn point named
TeleportSpot.
Key Features:
✅ Automatic Room Detection
- The script detects the current room (e.g.,
Room1) and teleports to the next one (Room2).
✅ Wave-Motion Dots
- The three dots bounce in a smooth sine wave pattern.
✅ Click-Only & Anti-Spam
- Players must click (not touch) the button.
- The button locks after one click to prevent spam.
✅ Centered UI on All Devices
- Uses
UDim2 for perfect scaling on mobile/PC/console.
Testing Instructions
- Place the script inside all
TeleportButton parts.
- Click the button in
Room1 → You should:
- See the loading animation.
- Teleport to
Room2 after 2 seconds.
- Click the button in
Room2 → You’ll go to Room3, and so on.
Troubleshooting
- Teleport doesn’t work?
Check:
- Room names (
Room1, Room2, etc.).
- Each room has
TeleportSpot.
- UI not centered?
The script automatically centers it—no adjustments needed.
- Dots not bouncing?
The wave motion is handled by math.sin()—it’s smooth by design.
Let me know if you want to add more mechanics (like puzzles, keys, or timers)! 😊