Skip to content

feat: TweenService #9

@TechHog8984

Description

@TechHog8984

https://create.roblox.com/docs/reference/engine/classes/TweenService

Tweens work on the following types:

  • number
  • boolean
  • CFrame
  • Rect
  • Color3
  • UDim
  • UDim2
  • Vector2
  • Vector2int16
  • Vector3
  • EnumItem

A Tween can be created targeting multiple properties of an Instance, however internally each property needs to be handled separately. This is because of the following (note the comments):

local TweenService = game:GetService("TweenService")

TweenService:Create(
    script.parent,
    TweenInfo.new(5),
    {
      BackgroundColor3 = Color3.fromRGB(230, 220, 100),
      Position = UDim2.fromOffset(200, 300)
    }
):Play()
-- script.Parent's color starts changing to yellow and position goes toward 200, 300

task.wait(0.8)

TweenService:Create(
    script.parent,
    TweenInfo.new(3),
    {
      Position = UDim2.fromOffset(500, 300)
    }
):Play()
-- script.Parent's position no longer goes toward 200, 300 but instead now 500, 300; the color, however, keeps going toward yellow as if nothing happened.

A new Tween being played will cancel any current tween with the same instance and properties. However, the previously-playing Tween object itself will only be canceled (PlaybackState set to Canceled and Completed fired) if all of its properties are present in the new tween. If the old Tween has properties not present in the new Tween, it will continue to play until either the time has elapsed or every one of its properties have been interrupted by new Tweens.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions