Trail

Show Deprecated

The Trail object is used to create a trail like an effect between two points. As the points move through space a texture is drawn on the plane the points define. This is commonly used to create effects to help visualize movements like tracer trails behind projectiles, footprints, tire tracks, and many other similar effects.

See Trails for more information.

Summary

Properties

Determines where the Trail will start drawing its segments.

Determines where the Trail will start drawing its segments.

Scales the light emitted from Trail when LightInfluence is 0.

The color of the trail segments throughout the lifetime of the trail.

Toggles whether a trail will be drawn or not.

If set to true, the trail textures will always face the camera.

Duration of the trail in seconds.

Sets how much the colors of the trail are blended with the colors behind them.

Determines the factor to which the Trail is influenced by the environment's lighting.

Sets the maximum length of the trail.

Minimum length of a trail's segment in studs.

The texture to display on the trail.

Sets length of texture if Trail.TextureMode is Wrap or Static. If mode is Stretch sets number of times texture will repeat.

Sets how the Texture will be drawn.

Sets the transparency of the Trail's segments over the trail's Trail.Lifetime.

A NumberSequence that scales the width of the Trail over the course of its lifetime.

Methods

Clear(): void  

Clears the segments of the trail.

Events

Properties

Attachment0

A Trail starts drawing its segments at the positions of its Trail.Attachment0 and *Attachment1.

When the Trail is Trail.Enabled it will record the positions of its attachments every frame. It will connect these positions to the positions of the attachments on the previous frame. This creates a polygon that is then filled in by the Trail's Trail.Color and Trail.Texture (if that Texture exists).

When created a Trail will not have any Attachments set by default. These will need to be set in order for the effect to work.

Changing the Attachments of a Trail while a trail is drawing will remove all of the segments the trail has already drawn.

Code Samples

Creating a Part With a Basic Trail

-- Create a new BasePart
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
-- Create 2 attachments
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2, 0, 0)
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2, 0, 0)
-- Create a new Trail
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
local color1 = Color3.fromRGB(15, 127, 254)
local color2 = Color3.fromRGB(255, 255, 255)
trail.Color = ColorSequence.new(color1, color2)
-- Tween part to display trail
local TweenService = game:GetService("TweenService")
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

Attachment1

A Trail starts drawing its segments at the positions of its Attachment0 and Trail.Attachment1.

When the Trail is Trail.Enabled it will record the positions of its attachments every frame. It will connect these positions to the positions of the attachments on the previous frame. This creates a polygon that is then filled in by the Trail's Trail.Color and Trail.Texture (if that Texture exists).

When created a Trail will not have any Attachments set by default. These will need to be set in order for the effect to work.

Changing the Attachments of a Trail while a trail is drawing will remove all of the segments the trail has already drawn.

Code Samples

Creating a Part With a Basic Trail

-- Create a new BasePart
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
-- Create 2 attachments
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2, 0, 0)
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2, 0, 0)
-- Create a new Trail
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
local color1 = Color3.fromRGB(15, 127, 254)
local color2 = Color3.fromRGB(255, 255, 255)
trail.Color = ColorSequence.new(color1, color2)
-- Tween part to display trail
local TweenService = game:GetService("TweenService")
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

Brightness

Scales the light emitted from Trail. By default, this property is 1 and can set to any number within the range [0, 10000].

Increasing the value of LightInfluence decreases the effect of Brightness. Brightness doesn't have any effect when LightInfluence is 1.

The color of a Trail can be set with the effect's Color property. This property determines what color the segments of the trail will have through their Trail.Lifetime.

Color is a ColorSequence, which means that the segments in a trail can shift between several colors. Note that if the color for a trail changes after some of the trail segments have been drawn, all of the old segments will be updated to match the new colors.

If a trail has a Trail.Texture then the Color property will tint that texture.

Trails with tinted textures

Any transparent components of a texture will not be tinted.

Code Samples

Creating a Trail with a Color Gradient

local trailEffect = script.Parent
local startColor = Color3.fromRGB(255, 0, 0)
local endColor = Color3.fromRGB(0, 0, 255)
local sequence = ColorSequence.new(startColor, endColor)
trailEffect.Color = sequence
Changing a Trail Color As It Is Drawing

local trailEffect = script.Parent
local firstColor = Color3.fromRGB(0, 255, 255)
local secondColor = Color3.fromRGB(255, 0, 0)
local firstSequence = ColorSequence.new(firstColor)
local secondSequence = ColorSequence.new(secondColor)
trailEffect.Color = firstSequence
task.wait(1.5)
trailEffect.Color = secondSequence

Enabled

The Enabled property determines whether a Trail will be drawn or not. This Enabled property defaults to true.

When enabled is true, the trail will create segments between the current position of its Trail.Attachment0 and the position of the attachments in the last frame.

If enabled is set to false while a trail is drawing no new segments will be drawn, but any existing segments will be cleaned up naturally when they reach the end of their Trail.Lifetime. If you would like to clean up any existing segments, you can use the Trail:Clear() function at the same time.

Code Samples

Clearing and Disabling a Trail

-- The function that tweens the part back and forth 15 studs
local DISTANCE = 15
local TweenService = game:GetService("TweenService")
local function tweenPart(part)
DISTANCE *= -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, DISTANCE)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end
-- Create a new BasePart
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
-- Create 2 attachments
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2, 0, 0)
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2, 0, 0)
-- Create a new Trail
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
local color1 = Color3.fromRGB(15, 127, 254)
local color2 = Color3.fromRGB(255, 255, 255)
trail.Color = ColorSequence.new(color1, color2)
-- Tween part, clear trail segments, and toggle trail between enabled/disabled
while true do
tweenPart(part)
trail:Clear()
trail.Enabled = not trail.Enabled
end
Setting a Trail's Enabled Property

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local dir = 15
while true do
trail.Enabled = not trail.Enabled
if trail.Enabled then
part.BrickColor = BrickColor.Green()
else
part.BrickColor = BrickColor.Red()
end
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

FaceCamera

The FaceCamera property determines whether the Trail is always drawn facing the camera. The default value is false.

If set to true, the trail textures will always face the camera. If set to false, the texture will be drawn in the direction of the distance between the trail's Trail.Attachment0 and Trail.Attachment1.

Note that changing this property immediately affects all existing and future trail segments. This means that all existing and new segments will adjust to face the player's camera or the direction of the attachments according to the property's new state.

FaceCamera Enabled

Demonstrating a trail with the FaceCamera property set to true.


local trail = script.Parent
trail.FaceCamera = true

FaceCamera Disabled

Demonstrating a trail with the FaceCamera property set to false.


local trail = script.Parent
trail.FaceCamera = false

Code Samples

Setting a Trail's FaceCamera Property

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.FaceCamera = true
trail.Parent = part
local dir = 15
while true do
dir = dir * -1
trail.FaceCamera = not trail.FaceCamera
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

Lifetime

The Lifetime property determines how long each segment in its Trail will last in seconds. Once a segment is drawn, it will wait for the given lifetime (measured in seconds) and then will disappear. The lifetime property defaults to 2 seconds, but can be set anywhere between 0.01 and 20.

The lifetime of a trail is also used by that effect's Trail.Color and Trail.Transparency properties to determine how each segment is drawn. Both of these properties are sequences, meaning that they define their values at certain keypoints in the segement's lifetime and then interpolate between the values as the segment ages.

If a trail's lifetime changes while there are still segments that the trail has drawn, these segments will immediately behave as if they always had the new lifetime. This means that if they have existed for longer than the lifetime they will be removed immediately.

Code Samples

Setting a Trail's Lifetime

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Lifetime = 0.4
trail.Parent = part
local dir = 15
local life = -5
while true do
dir = dir * -1
life = life * -1
trail.Lifetime = trail.Lifetime + life
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

LightEmission

The LightEmission Trail property sets how much the Colors of the trail are blended with the colors behind them. LightEmission uses additive blending to combine the colors, meaning the RGB values of the colors are added together to determine the displayed color. This addition is weighted by the value of LightEmission.

When changed this property instantly affects all particles owned by the emitter, both current and future particles.

This property is not related to the dynamic lighting engine of Roblox. If you need your trail to emit light, it is recommended to create parts with PointLight that follow the path of the trail.

Code Samples

Creating a Trail that Emits Light

local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2, 0, 0)
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2, 0, 0)
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.LightEmission = 1
-- Tween part to display trail
local TweenService = game:GetService("TweenService")
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

LightInfluence

LightInfluence determines the factor the light in the environment affects the appearance of the Trail. A value of zero (0) ensures no influence which allows a trail to be visible even in complete darkness.

Changing this property immediately affects all existing and future segments of the trail.

See also:

Code Samples

Setting a Trail's Light Influence

local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
Lighting.Brightness = 0
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.LightInfluence = 1
trail.Parent = part
local dir = 15
local influence = 1
while true do
dir = dir * -1
influence = influence * -1
trail.LightInfluence = trail.LightInfluence + influence
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

MaxLength

The MinLength of a Trail determines the maximum length of each of the segments in the trail.

Note that changing MaxLength will only affect new segments that are drawn – any old segments that have already been drawn will maintain their current length.

This value can be any number greater than or equal to 0, and defaults to 0. If the property is set to 0, the maximum length will be infinity - meaning that the trail will not have a maximum length.

Please note that, even if this property is 0, or another large number, the trail is still constrained by its Trail.Lifetime. Old segments will be erased if they reach the end of their lifetime, even if the trail is shorter than the maximum length. Be sure to set both properties fittingly.

This property can also be used alongside the Trail.MinLength property, which determines the minimum length trail must before before it is drawn.

Demonstration of trail length.

Code Samples

Setting a Trail's MaxLength

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Lifetime = 10
trail.MaxLength = 8
trail.Parent = part
local dir = 30
local length = 6
while true do
dir = dir * -1
length = length * -1
trail.MaxLength = trail.MaxLength + length
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

MinLength

The MinLength of a Trail determines the minimum length of each of the segments in the trail.

If neither of the trail's Trail.Attachment0 or Trail.Attachment1 have moved at least the minimum length in studs, then no new segments will be created and the endpoints of the current segment will be moved to the current position of the attachments.

Note that changing MinLength will only affect new segments that are drawn – any old segments that have already been drawn will maintain their current length.

This value can be any number greater than or equal to 0, and defaults to 0.1.

This property can also be used alongside the Trail.MaxLength property, which determines the maximum length trail may be before its oldest segments are erased.

Minimum length of a trail's segment in studs.

Code Samples

Setting a Trail's Minimum Length

local trail = script.Parent
trail.Lifetime = 4
while true do
task.wait(3)
trail.MinLength = 10
task.wait(3)
trail.MinLength = 0.1
end

Texture

The Texture property is the texture to draw on a Trail's segments. This property sets which image asset to use for the texture. This is set the same way as textures in other objects, such as ImageLabel or ParticleEmitter. The simplest way to set this property is to use an image uploaded to the Asset Manager (this requires the current place to be Published to Roblox).

If a texture is not provided, then just the Trail.Color of the Trail will be used. With a texture, the trail will draw the texture as its attachments move.

A trail with a pawprint texture.

Textures can be displayed in a variety of different ways based on the trail's Trail.TextureMode and Trail.TextureLength properties.

Code Samples

Creating a Trail With a Pawprint Texture

local trail = script.Parent
local textureId = "rbxassetid://909814149"
trail.Texture = textureId

TextureLength

This property determines how Trail.Textures are drawn by Trail. The behavior of TextureLength is determined by the Trail.TextureMode of its trail.

If the TextureLength is changed after its trail has drawn some of its segments, the new length will only be applied to new segments being drawn -- old segments will be unaffected.

This value can be any number greater than 0 and defaults to 1.

Code Samples

Setting a Trail's Texture Length

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local textureId = "rbxassetid://909814149"
trail.Texture = textureId
trail.TextureMode = Enum.TextureMode.Static
trail.TextureLength = 4
local dir = 15
local length = 2
while true do
dir = dir * -1
length = length * -1
trail.TextureLength = trail.TextureLength + length
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

TextureMode

A Trail's TextureMode property determines how the effect's Trail.Texture (if any) is drawn. The behavior of the texture in each mode is also very much dependent on the effect's Trail.TextureLength property. Note that changing an effect's TextureMode after some of the trail has been drawn will affect all of the previously drawn segments.

TextureMode defaults to Stretch.

Stretch

Stretch is the default TextureMode for Trails. In this mode the texture will be tiled a number of times equal to the number defined by TextureLength. It will stretch these tiles evenly to fit the entire length of the drawn trail. For example, if TextureLength is set to 4 then the texture will always repeat 4 times in the trail, no matter how long or short the trail is.

Demonstrating a trail texture using the stretch mode.

Wrap

In the Wrap mode, the texture will start at the attachment points and will move as the attachments move. As soon as the attachments have moved a number of studs equal to the TextureLength, then the texture will repeat. The longer the trail is, the more times the texture will repeat.

Demonstrating a trail texture using the wrap mode.

Static

In the Static mode, the texture will start at the initial position of the trail and will be drawn as the attachments move. Once the attachments move a number of studs equal to the TextureLength, then the texture will repeat.

Demonstrating a trail texture using the static mode.

Code Samples

Setting a Trail's Texture Mode

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local textureId = "rbxassetid://909814149"
trail.Texture = textureId
trail.TextureMode = Enum.TextureMode.Static
trail.TextureLength = 4
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

Transparency

The Transparency property of a Trail sets how transparent the segments of the trail are over the trail's Trail.Lifetime. This value is a NumberSequence, meaning it can be a static value or can change throughout the lifetime of the trail segments.

The values in the NumberSequence can be any number, but the effective range of transparency is 0 (completely opaque) to 1 (completely see-through). The Transparency property for TrailEffects defaults to 0.5.

Code Samples

Setting a Trail's Transparency: Single Value Sequence

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local singleValueSequence = NumberSequence.new(0.8)
trail.Transparency = singleValueSequence
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end
Playing in Third Person

local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.CameraMode = Enum.CameraMode.Classic
Setting a Trail's Transparency: Multi Value Sequence

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local keypoints = {}
table.insert(keypoints, NumberSequenceKeypoint.new(0, 1))
table.insert(keypoints, NumberSequenceKeypoint.new(0.25, 0))
table.insert(keypoints, NumberSequenceKeypoint.new(1, 1))
local multiValueSequence = NumberSequence.new(keypoints)
trail.Transparency = multiValueSequence
local dir = 15
while true do
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

WidthScale

The WidthScale property is a NumberSequence that scales the width of the Trail over the course of its lifetime.

This property can range from 0 to 1. The value of the property influences the width of the trail by setting the trail's width to the product of:


(distance between trail's attachment0 and attachment1 in studs) * (the value of WidthScale)

For example, if the trail's attachments are 2 stud's apart, and the value of this property is 0.5, the trail's width will be 1 stud and the trail will be centered in between the two attachments.

If you would like to hide the trail entirely, consider setting Trail.Enabled to false.

Code Samples

Scaling a Trail's Width

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
part.Parent = workspace
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Position = Vector3.new(-2, 0, 0)
attachment0.Parent = part
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Position = Vector3.new(2, 0, 0)
attachment1.Parent = part
local trail = Instance.new("Trail")
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = part
local dir = 15
local i = 1
local sizes = { 0.25, 0.75 }
while true do
i = (i + 1) % 2
print(i)
trail.WidthScale = NumberSequence.new(sizes[i + 1])
dir = dir * -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, dir)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end

Methods

Clear

void

The Clear function clears the segments of the Trail. This means that any trail that has been drawn will be erased when this function is called, even if that segment's Trail.Lifetime duration has not yet been reached.

While this is less noticeable for trails with shorter lifetimes, this is useful when cleaning up trails that have a longer lifetime, or for cases where the trail is removed when a certain game action occurs.

Calling this function will only affect old segments that have already been done. It will not affect the drawing of any new trail segments after this function call. If you would like to clear existing trail segments, and temporarily prevent new segments from being drawn, consider toggling the trail's Trail.Enabled property to false at the same time.


Returns

void

Code Samples

Clearing and Disabling a Trail

-- The function that tweens the part back and forth 15 studs
local DISTANCE = 15
local TweenService = game:GetService("TweenService")
local function tweenPart(part)
DISTANCE *= -1
local goal = {}
goal.Position = part.Position + Vector3.new(0, 0, DISTANCE)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(5)
end
-- Create a new BasePart
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(0, 5, 0)
-- Create 2 attachments
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2, 0, 0)
local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2, 0, 0)
-- Create a new Trail
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
local color1 = Color3.fromRGB(15, 127, 254)
local color2 = Color3.fromRGB(255, 255, 255)
trail.Color = ColorSequence.new(color1, color2)
-- Tween part, clear trail segments, and toggle trail between enabled/disabled
while true do
tweenPart(part)
trail:Clear()
trail.Enabled = not trail.Enabled
end

Events