Collapse Sidebar




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

This example demos setting a trail’s max length.

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 initially set the trail’s max length to 8. Then, to demonstrate the effects of changing the trail length, we alternate between a trail length of 2 and 8 every 5 seconds by adding and subtracting 6 from the length.

In order to best demonstrate the effect of max length, and how it will limit how long a trail is before old segments are erased, the example sets the Trail/Lifetime of the trail to 10. Since the lifetime allows for a trail much longer than 2 and 8, the example demonstrates the full effects of changing the max length property.

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

Demonstrating the static trail texture mode.

-- 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
trail.Lifetime = 10
trail.MaxLength = 8

-- Tween part to display trail
local TweenService = game:GetService("TweenService")

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)