Roblox GuidebookKnowledge base
English ⌄

Studio / ROBLOX

TweenService in Roblox Studio: a menu animation that survives repeated clicks

Build a small menu test, identify competing tweens and handle cancellation without treating it as success.

Updated:

Define the menu's final states first #

Imagine a workshop menu with a blue card showing three available tools. The player can open it, close it and change their mind before the movement finishes. Write down two destinations before choosing an easing curve: the card's open position and its closed position. These are the intended interface states. A half-open card is a temporary visual position, not a third permission level. Keep the close control outside the moving card during the first experiment so it remains reachable throughout the journey. Use a separate test place rather than replacing a working shop immediately.

Describe the problem precisely: which button was pressed, where the card stopped and what should have happened next. “The animation is broken” hides several different cases. The handler might never run; the wrong object might move; another handler might change the same property; an old completion callback might overwrite a newer decision. Our experiment changes only Position. It does not grant tools, spend currency or verify a purchase. This boundary makes a visual failure easier to reproduce without turning each attempt into a transaction. The example is a proposed Studio exercise, not a recording of an Engine test performed here.

Prepare one visible card and two stationary buttons #

In a new test ScreenGui under StarterGui, add a Frame named Panel and two sibling TextButtons named OpenButton and CloseButton. Give Panel a contrasting background and a modest size that fits a phone viewport. Place both buttons away from the card's intended route. Put the LocalScript shown below directly under this ScreenGui. The code uses direct child references, so names and parent relationships must match. If Output reports that a member is missing, repair that tree before changing the animation settings. A misspelled button is a different problem from interrupted movement.

Our chosen layout uses a centered anchor and two scale-based positions. You can change the destinations after the first successful check, but retain enough of the closed card on screen to observe its location during debugging. Test in play mode and inspect the player's actual GUI rather than expecting the StarterGui template to show runtime progress. Begin with one press and let the card settle. Record its final Position and whether both controls remain available. Only then introduce rapid alternating input. Starting with overlapping clicks makes it harder to know whether the basic setup ever worked.

Three independent transition-control checksOpen full-size image ↗
Three independent transition-control checks

Give the current request ownership of completion #

The code assigns each requested transition a number. It increases that number before cancelling the previous tween. A completion handler checks both that number and the reported playback state before updating the final-state message. This is our small ownership rule: an older request may finish or be cancelled, but cannot announce that a newer request succeeded. The active variable keeps the currently owned tween. The requestedOpen variable records the requested destination, while settledOpen records the last destination actually accepted as completed. Neither is an authorization check for gameplay rewards.

Read the example as one script with one owner for Panel.Position. Connect each button once. Press OpenButton, wait for completion and inspect the message; then press CloseButton and repeat. Next alternate the buttons while the card moves. The last accepted request should determine the destination. If the result differs, preserve the exact input order and Output text. Do not add a second copy of the script as a fix. A duplicate could introduce another owner for the same card and make an otherwise sensible transition look unreliable. A readable ownership rule matters more here than a complicated easing effect.

local TweenService = game:GetService("TweenService")
local gui = script.Parent
local panel = gui.Panel
local openButton = gui.OpenButton
local closeButton = gui.CloseButton

local closed = UDim2.fromScale(0.5, 0.8)
local opened = UDim2.fromScale(0.5, 0.4)
panel.AnchorPoint = Vector2.new(0.5, 0.5)
panel.Position = closed

local revision = 0
local active = nil
local requestedOpen = false
local settledOpen = false
local info = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local function setOpen(open)
    revision += 1
    local mine = revision
    requestedOpen = open
    if active then
        active:Cancel()
        active = nil
    end
    local target = if open then opened else closed
    local tween = TweenService:Create(panel, info, {Position = target})
    active = tween
    local connection
    connection = tween.Completed:Connect(function(state)
        connection:Disconnect()
        if mine ~= revision then return end
        active = nil
        if state ~= Enum.PlaybackState.Completed then return end
        settledOpen = open
        print("Menu settled:", settledOpen, "Requested:", requestedOpen)
    end)
    tween:Play()
end

openButton.Activated:Connect(function() setOpen(true) end)
closeButton.Activated:Connect(function() setOpen(false) end)

Separate cancellation from a completed destination #

Roblox documents that a newer tween targeting the same property cancels the older one. Its Completed event also reports cancellation; the event name alone is therefore insufficient evidence that the card reached its destination. Our callback accepts only Enum.PlaybackState.Completed for the current request. Notice the difference between stopping movement and choosing a new destination. Cancellation leaves the property's current value in place. The next tween starts from that visible position towards the newly requested target. We do not manually snap the card back to the start each time a button is pressed.

For a separate pause experiment, keep a reference to one tween, pause it during playback and resume that same object. Pause retains its progress, whereas cancellation resets the tween's progress variables. Do this as a separate exercise, not by adding pause buttons into the example without defining their behavior. Ask what should happen if Close is pressed while paused: resume the old opening request or replace it with a closing request? Write the answer before coding. Ambiguous product rules often look like animation bugs because different handlers implement different answers. A cancelled opening should never masquerade as a successfully opened menu.

Diagnose the writer before changing the duration #

If the card jumps, search the test project for assignments to Panel.Position and for every tween created for that panel. Temporarily disable the other writers in the isolated test, then repeat the same input sequence. Layout objects or another menu controller can also make your expected destination misleading. Change one factor at a time and compare observations. Increasing the duration may make a conflict easier to see, but it does not resolve competing ownership. Likewise, changing an easing curve cannot correct a wrong object reference or a callback that ignores the request number.

If the callback prints the correct final state but the menu still looks wrong, inspect the visible result separately: the card's size, clipping, layering and actual position on the current screen. A correct status message cannot prove readability. Keep the target area free of important controls and check whether the moving panel obscures the close button. In a real game, define a reduced-motion option and a direct final-state path rather than forcing every visitor through decorative movement. That extension needs its own behavior rules; the tutorial code intentionally demonstrates only ownership of two animated destinations.

Three menu test scenarios: expected outcomesOpen full-size image ↗
Three menu test scenarios: expected outcomes

Use a repeatable acceptance checklist #

Check a quiet opening, a quiet closing, Open then Close during movement, and several alternating presses ending with Open. Record the last requested destination, final Position and accepted completion message for each case. Then repeat on a narrow viewport. The table below describes expected outcomes, not results already observed in Roblox Studio. A screenshot of a correctly placed card cannot prove cancellation behavior, and a console message cannot prove that the close button is reachable. Keep these checks separate so a failure points to the correct layer of the interface.

Before moving the approach into a shop or inventory, add tests for respawn, GUI replacement and closing the whole screen. Decide which script owns cleanup when the interface is destroyed. Do not move currency grants into an animation callback: visual completion is not a receipt or server validation. Save the isolated demonstration and a short reproduction sequence with the game's development notes. The useful deliverable is a predictable menu that responds to the latest intent, together with evidence from your own target devices. More simultaneous effects can be added later after this simple transition has an understandable result.

ActionExpected outcomeVerification status
Open, then waitOpen destinationStudio: still to test
Open, then CloseClosed; stale success rejectedStudio: still to test
Rapid alternating pressesLatest request sets destinationStudio: still to test
Narrow viewportClose button stays reachableStudio: still to test

Original sources

Roblox Creator Hub — UI animation/tweens
Roblox Creator Hub — TweenService
Roblox Creator Hub — Playback, cancellation and Completed
Roblox Creator Hub — TweenInfo