I’m trying to make a Beam Manager module script for my lasers in a core/reactor game, and I’m having major issues with tweening/lerping the transparency and colour. I’ve looked everywhere but couldn’t find any help. Here is my current code:
local Transparency = function(laser,transparency,style,styleTime)
if typeof(laser) == "string" then
laser = beamsFolder[laser]
end
--[[
if transparency:isA("Number") then
transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0, transparency)
}
end
]]--
if style == "Tween" then
local beamTransparency = laser.Beam.Transparency.Keypoints[1].Value
for i = 0, 1, wait() / styleTime do
laser.Beam.Transparency = NumberSequence.new(beamTransparency:lerp(transparency, i))
wait()
end
else
laser.Beam.Transparency = NumberSequence.new(transparency)
end
end
local Color = function(laser,color,style,styleTime)
if typeof(laser) == "string" then
laser = beamsFolder[laser]
end
if style == "Tween" then
local beamColor = beamsFolder[laser].Beam.Color.Keypoints[1].Value
for i = 0, 1, wait() / styleTime do
beamsFolder[laser].Beam.Color = ColorSequence.new(beamColor:lerp(color, i))
wait()
end
else
beamsFolder[laser].Beam.Color = ColorSequence.new(color)
end
end
Try using a NumberValue/Color3Value and then on .Changed, update the property. Colour sequences and number sequences don’t support tweening or lerping unfortunately.
I have 8 lasers to work with, and then I have multiple more decorational ones that I have to work with for each of these 8 lasers. I’ll see what I can do though.
I’ll try and help you out here. Something like this should work:
local transparency = function(laser, transparency, style, styleTime)
if type(laser) == 'string' then -- try using type if you aren't specifically looking for roblox datatypes as it's quite a bit faster. This is micro-optimization though and doesn't make a huge difference. You could also probably do laser = beamsFolder[laser] or laser
laser = beansFolder[laser]
end
if style == 'Tween' then
local transparencyValue = Instance.new('NumberValue')
local beamTransparency = laser.Beam.Transparency.Keypoints[1].Value
transparencyValue.Value = beamTransparency
tweenService:Create(transparencyValue, TweenInfo.new(styleTime, Enum.EasingStyle.Linear), Value = transparency):Play()
transparencyValue.Changed:Connect(function()
laser.Beam.Transparency = NumberSequence.new(transparencyValue.Value)
end)
end
end
Doing this with ColorSequences would essentially be the same, except instead of using a NumberValue, you’d use a Color3Value.
local Transparency = function(laser,transparency,style,styleTime)
if type(laser) == 'string' then
print(laser)
laser = beamsFolder[laser]
end
--[[
if transparency:isA("Number") then
transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0, transparency)
}
end
]]--
if style == "Tween" then
local transparencyValue = laser:FindFirstChild("Transparency")
print(transparencyValue)
local beamTransparency = laser.Beam.Transparency.Keypoints[1].Value
transparencyValue.Value = beamTransparency
TS:Create(transparencyValue, TweenInfo.new(styleTime, Enum.EasingStyle.Linear), {Value = transparency}):Play()
transparencyValue.Changed:Connect(function()
laser.Beam.Transparency = NumberSequence.new(transparencyValue.Value)
end)
else
laser.Beam.Transparency = NumberSequence.new(transparency)
end
end
Wait I need to find the descendant of the BEAM, not the PART.
Oh gotcha. Are you passing a NumberSequence value to the function? It should be a number. Pretty sure that’s the only time the transparency variable gets assigned.