I usually don’t ever use for i loops, but in this situation it seems like it is my only solution. My goal is to tween a beam’s transparency, but tween doesn’t have the ability to tween beam transparency values directly. So the only way to do this is to use a for i loop to get a number value and replace it in the number sequence. Is there any other solution other than for i loops? If there is no other solution, then is a wait() always required in a for i loop? I also do not like wait().
for i = 0.5,1.01,0.01 do
beam.Transparency = NumberSequence.new(i,i)
wait()
end
I also tried using a NumberSequence.new() function, and says the property cannot be tweened. Then I would suggest a for loop is the way to go, unless there’s anything else out there.
While NumberSequences are not valid property that can be tweened, we can simply tween a separate number by tweening a numbervalue, and changing the beams transparency to its value. This is also a useful technique for tweening models CFrame e.t.c
local TweenService = game:GetService("TweenService")
local function TweenTransparency(Beam: Beam, Start: number, Goal: number)
local NumberValue = Instance.new("NumberValue")
NumberValue.Value = Start
NumberValue.Changed:Connect(function(Value)
Beam.Transparency = NumberSequence.new(Value)
end)
local Tween = TweenService:Create(NumberValue, TweenInfo.new(1), {Value = Goal})
Tween:Play()
Tween.Completed:Connect(function()
NumberValue:Destroy()
Tween:Destroy()
end)
end
TweenTransparency(workspace.Beam, 0.5, 1)