Why doesn't my rainbow trail script work?

Hi!

So I’ve been working on a hangout/dancing game, and I have glowsticks that you hold when you dance. I made a rainbow one too.

As you might know TweenService cannot tween trails normally, so I made a hacky solution that should work, however it isn’t. Here is the issue:

As you can see, the stick itself tweens but the color does not change. Here is the script:

local Part = script.Parent
local Trail = Part:WaitForChild("Trail")
local Val = Instance.new("Color3Value")

Val.Value = Color3.new(0,0,0)

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local function SimpleTween(Object, Length, Style, Direction, Properties)
	local Tween = TweenService:Create(
		Object,
		TweenInfo.new(Length, Enum.EasingStyle[Style].Value, Enum.EasingDirection[Direction].Value),
		Properties
	)

	Tween:Play()
	Tween.Completed:Wait()
	Tween:Destroy()
end
while true do
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(1,0,0) })
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(1,1,0) })
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(0,1,0) })
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(0,1,1) })
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(0,0,1) })
	SimpleTween(Part, 1, "Linear", "Out", { Color = Color3.new(1,0,1) })
end

RunService.Heartbeat:Connect(function()
	Val.Value = Part.Color
	Trail.Color = ColorSequence.new(Val.Value)
end)

Some help would be appreciated!

Thank you! :slightly_smiling_face:

It’s probably something simple I overlooked. :flushed:

RunService.Heartbeat is below a while loop that will never finish thus making the RunService.Heartbeat never function

Then what should I replace it with? Spawn? Coroutine?

Edit: Whoops, fixed it. Forgot to add a spawn. :man_facepalming: Thank you @LegosAreGood05!

Instead of using tweens to animate the color of the beam use a variable to control the hue of the beam color

I prefer to use Tweens, as they looked cleaner and perform better. My issue was I left out threading, and should have added a spawn. Thank you for your help anyway!