I’m not sure if it should be doing this…
When I click, it does print “on”
But releasing prints a lot of “off”
If you still prefer to use TweenService for the easing styles, do this (heavy edit from latest code posted by @SuguruDev:
local beam = game.Workspace.Spotlights.Spotlight1.Arm.Head.Lens.AttG.Beam
local colour = beam.Color.Keypoints[1].Value
local Time = 0.3
local offColor, onColor = Color3.new(0, 0, 0), Color3.new(1, 1, 1) -- Set colors here.
local proxyNumber = Instance.new("NumberValue") -- A NumberValue for us to tween.
local proxyNumberOffAnimation = game:GetService("TweenService"):Create(
proxyNumber,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{Value = 0}
)
proxyNumber.Changed:Connect(function(value : number) -- Tweening a NumberValue actually fires .Changed every frame.
beam.Color = ColorSequence.new(
if value < 0.0001 then -- Negligible darkness.
offColor
elseif value > 0.9999 then -- Negligible brightness.
onColor
else
offColor:Lerp(onColor, math.clamp(value, 0, 1)) -- math.clamp ensures that the value is between 0 and 1.
)
end)
game.ReplicatedStorage.SpotlightStart.OnServerEvent:Connect(function(player, beam)
if proxyNumberOffAnimation.PlaybackState == Enum.PlaybackState.Playing then
proxyNumberOffAnimation:Cancel()
end
proxyNumber.Value = 1
end)
game.ReplicatedStorage.SpotlightStop.OnServerEvent:Connect(function(player, beam)
proxyNumberOffAnimation:Play()
end)
Should “NumberValue” be put as a nickname or an actual value?
Instance.new("NumberValue")
creates a new NumberValue item.
If you hover over it, does it say “Statement spans multiple lines; use indentation to silence.”? It shouldn’t raise any errors. Leave it be or add indentation before “proxyNumber”.
Works!
Thank you!
(Also thank you Cloud)
Also extra question:
How can this system be implemented for a light source? (SpotLight, PointLight, etc.)
Simple. Make a new Tween. The proxyNumber
is used only for the ColorSequence:
local tweenService = game:GetService("TweenService")
local beam = game.Workspace.Spotlights.Spotlight1.Arm.Head.Lens.AttG.Beam
local colour = beam.Color.Keypoints[1].Value
local Time = 0.3
local offColor, onColor = Color3.new(0, 0, 0), Color3.new(1, 1, 1) -- Set colors here.
local pathToLightSource = ???
local proxyNumber = Instance.new("NumberValue") -- A NumberValue for us to tween.
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local lightSourceTween = tweenService:Create( -- We can simply separate the light's tween from the ColorSequence workaround.
pathToLightSource,
tweenInfo,
{Brightness = 0}
)
local proxyNumberOffAnimation = tweenService:Create(
proxyNumber,
tweenInfo,
{Value = 0}
)
proxyNumber.Changed:Connect(function(value : number) -- Tweening a NumberValue actually fires .Changed every frame.
beam.Color = ColorSequence.new(
if value < 0.0001 then -- Negligible darkness.
offColor
elseif value > 0.9999 then -- Negligible brightness.
onColor
else
offColor:Lerp(onColor, math.clamp(value, 0, 1)) -- math.clamp ensures that the value is between 0 and 1.
)
end)
game.ReplicatedStorage.SpotlightStart.OnServerEvent:Connect(function(player, beam)
if proxyNumberOffAnimation.PlaybackState == Enum.PlaybackState.Playing then
proxyNumberOffAnimation:Cancel()
lightSourceTween:Cancel()
end
proxyNumber.Value = 1
pathToLightSource.Brightness = 1
end)
game.ReplicatedStorage.SpotlightStop.OnServerEvent:Connect(function(player, beam)
proxyNumberOffAnimation:Play()
lightSourceTween:Play()
end)
Do I merge this with the same script for the beam?
No, that’s the entire script. Simply change the ???
in local pathToLightSource
to where your light is.
Doesn’t seem to show light still.
Where is the light source located?
Does the output show any errors related to the script?
Scratch that, I just forgot to change the light color back to white, since it only changes brightness.
Thank you!
Hmm… Probably the light is too dark or too short? What’s your light’s default settings? Also, try a higher number for when the lights will be turned on.
pathToLightSource.Brightness = 10 -- 10, for example?
Edit: Ah okay. You’re welcome.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.