I understand your concerns! I'll update the script to address everything you mentioned:
- Click Only: The button will only respond to clicks (or taps on mobile), not when players walk over it. I've removed the touch detection entirely.
- One-Time Click: The button can only be clicked once per player to prevent multiple loading screens. After a player clicks, it won't trigger again for them.
- Centered UI for All Devices: I've used Roblox's UDim2 scaling system to ensure the UI is perfectly centered on all screen sizes (PC, mobile, consoles). This means it adapts automatically.
- Bouncing Dots: The dots will now visually bounce up and down (not just change text). They'll be positioned below the "Loading" text, as you described.
Here's the complete, updated script. You can copy and paste it directly into a Script inside your button part in Roblox Studio. No need to create any UI elements or additional scripts – this one handles everything.
Updated Script
-- Centered Loading Animation with Bouncing Dots + One-Time Click Only
-- Copy/paste this into a Script inside your button part in Roblox Studio
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 (e.g., a part in the next room)
local loadingTime = 2 -- Seconds to show loading screen (change if needed)
-- ======================== --
-- Add ClickDetector if not already present
if not button:FindFirstChild("ClickDetector") then
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = button
end
local clickDetector = button.ClickDetector
-- Track which players have clicked to prevent multiple triggers
local clickedPlayers = {} -- Stores players who have already clicked
-- Create UI elements with proper centering
local function createLoadingUI(player)
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "LoadingScreen"
screenGui.Parent = playerGui
-- Black background (full screen, starts above)
local blackFrame = Instance.new("Frame")
blackFrame.Name = "BlackFrame"
blackFrame.Size = UDim2.new(1, 0, 1, 0) -- Scales to full screen on all devices
blackFrame.Position = UDim2.new(0.5, 0, -1, 0) -- Start above screen, centered horizontally
blackFrame.AnchorPoint = Vector2.new(0.5, 0) -- Helps with smooth sliding
blackFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
blackFrame.BorderSizePixel = 0
blackFrame.Parent = screenGui
-- Loading text (centered horizontally, positioned at top of center area)
local loadingText = Instance.new("TextLabel")
loadingText.Name = "LoadingText"
loadingText.Size = UDim2.new(0.8, 0, 0.2, 0) -- Scales with screen width
loadingText.Position = UDim2.new(0.5, 0, 0.4, 0) -- Vertically at 40% (center area)
loadingText.AnchorPoint = Vector2.new(0.5, 0.5) -- Centers the text itself
loadingText.BackgroundTransparency = 1
loadingText.Text = "Loading"
loadingText.TextColor3 = Color3.fromRGB(255, 255, 255)
loadingText.TextScaled = true -- Scales text to fit all devices
loadingText.Font = Enum.Font.SourceSansBold
loadingText.Parent = blackFrame
-- Dots text (below loading text, will bounce up and down)
local dotsText = Instance.new("TextLabel")
dotsText.Name = "DotsText"
dotsText.Size = UDim2.new(0.3, 0, 0.1, 0) -- Smaller size, scales with screen
dotsText.Position = UDim2.new(0.5, 0, 0.55, 0) -- Starts below loading text (at 55% vertical)
dotsText.AnchorPoint = Vector2.new(0.5, 0.5) -- Centers the dots
dotsText.BackgroundTransparency = 1
dotsText.Text = "..."
dotsText.TextColor3 = Color3.fromRGB(255, 255, 255)
dotsText.TextScaled = true
dotsText.Font = Enum.Font.SourceSansBold
dotsText.Parent = blackFrame
return blackFrame, loadingText, dotsText, screenGui
end
-- Handle teleportation to the named part
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 or Model)")
return
end
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
character.HumanoidRootPart.CFrame = targetPart.CFrame -- Teleport to the part's position
end
end
-- Animation sequence with bouncing dots
local function showLoadingAnimation(player)
local blackFrame, loadingText, dotsText, screenGui = createLoadingUI(player)
-- Slide in animation for black frame
local slideIn = TweenService:Create(
blackFrame,
TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{Position = UDim2.new(0.5, 0, 0.5, 0)} -- Slide to center of screen
)
slideIn:Play()
-- Bouncing dots animation (moves up and down)
local originalPosition = dotsText.Position
local bounceTweenUp = TweenService:Create(dotsText, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Position = UDim2.new(0.5, 0, 0.55, -20)}) -- Bounce up
local bounceTweenDown = TweenService:Create(dotsText, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {Position = originalPosition}) -- Bounce down
local isBouncing = true
spawn(function()
while isBouncing and wait(1) do -- Bounce every second (adjust wait time if needed)
bounceTweenUp:Play()
bounceTweenUp.Completed:Wait()
bounceTweenDown:Play()
bounceTweenDown.Completed:Wait()
end
end)
-- Wait for loading time
wait(loadingTime)
isBouncing = false -- Stop the bouncing animation
-- Teleport the player
handleTeleport(player)
-- Slide out animation
local slideOut = TweenService:Create(
blackFrame,
TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
{Position = UDim2.new(0.5, 0, 1.5, 0)} -- Slide off the bottom of the screen
)
slideOut:Play()
slideOut.Completed:Connect(function()
screenGui:Destroy() -- Clean up UI
end)
end
-- Click detection (only once per player)
clickDetector.MouseClick:Connect(function(playerWhoClicked)
if not clickedPlayers[playerWhoClicked] then -- Check if player hasn't clicked yet
clickedPlayers[playerWhoClicked] = true -- Mark player as having clicked
showLoadingAnimation(playerWhoClicked)
else
warn("Player has already clicked this button!")
end
end)
How to Set This Up in Roblox Studio
-
Create Your Button:
- Add a part (like a cube or button model) in your room.
- Insert a Script into this part.
- Copy and paste the script above into the Script.
-
Create the Teleport Target:
- In Workspace, add a part (e.g., a small platform) where you want players to teleport.
- Name it exactly
NextRoomPart (you can change this in the script's teleportTargetName if you want a different name).
-
Test It:
- Press Play in Roblox Studio.
- Click the button (don't walk over it – it only works on click now).
- You should see:
- A black screen slides down from the top.
- "Loading" text centered on the screen.
- Dots below it that bounce up and down visually.
- After 2 seconds, you teleport to the
NextRoomPart.
- The screen slides away, and it only works once per player.
Key Improvements Explained:
- Click Only: I removed the Touched event, so the button only activates on click (works on PC with mouse or mobile with tap).
- One-Time Click: The
clickedPlayers table ensures that once a player clicks, they can't trigger the animation again. This stops multiple loading screens.
- Centered for All Devices: Used
UDim2 with scale (e.g., UDim2.new(0.5, 0, 0.4, 0)) and AnchorPoint to make the UI adapt to any screen size. It should look centered on PC, mobile, and consoles.
- Bouncing Dots: Now, the dots bounce up and down using TweenService. They're positioned below the "Loading" text (at 55% vertical) and animate smoothly.
- No Overlap Issues: The UI is created and destroyed for each player, so it shouldn't overlap or cause problems.
If you test this and it's not quite right (e.g., the bounce speed or positioning), let me know the details, and I can fine-tune it further! 😊