We use cookies on this site to enhance your user experience
Collapse Sidebar




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

This example demos the functionality of trails.

In order to do this, we must first create a BasePart, part, which will be the parent of the trail.

Then, we create two attachments, attachment0 and attachment1, both parented to part. The positions of these two attachments, more importantly the distance between them, determines where the trail is drawn as part moves.

For these attachments to create a trail as described, we create a new Trail and parent it to part. We then connect attachment0 to Trail/Attachment0 and attachment1 to Trail/Attachment1.

In this example, we set the Trail/Color to a fade between blue and white using a DataType/ColorSequence. For more info on how to set a trail’s color in a script, see the Trail/Color's documentation.

Finally, to demo the alignment the example relies on TweenService's TweenService/Create to move part back and forth. As the part moves, the trail is drawn.

-- 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
color1 = Color3.new(15/255,127/255,254/255)
color2 = Color3.new(255/255,255/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)