roblox how to tween part color
To tween a part color in Lua for Roblox, you can use the following steps:
- Create a part and set its color to the starting color.
- Use the TweenService to create a new tween.
- Define the properties of the tween, such as the part, the color property, the easing style, and the duration.
- Start the tween using the :Play() method.
Here's an example of the code:
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.Size = Vector3.new(4, 4, 4)
part.Position = Vector3.new(0, 5, 0)
part.BrickColor = BrickColor.new("Bright blue")
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(
2, -- duration
Enum.EasingStyle.Linear, -- easing style
Enum.EasingDirection.Out, -- easing direction
-1, -- repeat count (-1 means infinite)
true, -- reverses
0 -- delay time
)
local colorTween = tweenService:Create(part, info, {Color = Color3.new(1, 0, 0)})
colorTween:Play()
This code creates a new part, sets its initial color to bright blue, defines a tween with a duration of 2 seconds and a linear easing style, and then starts the tween to change the part's color to red over the specified duration.