How do I make ambient lighting gradually change?

Hey, so I’ve been working on the lighting of a showcase that I’ve built and I was trying to get the ambient lighting to fade from one value to another once a brick was touched. So far, I’ve managed to get it to just change suddenly but I’m not a scripter and I have no idea how to make it gradually change.

This is what I’ve got so far:

local AmbientChange = false

game.workspace.Detector.Touched:Connect(function(hit)
    AmbientChange = true
    if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
        if AmbientChange == true then
            game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
            wait (1)
            game.Lighting.Ambient = Color3.fromRGB(118, 109, 89)   
        end
    end
end)

1 Like

TweenService
TweenInfo

local TweenService = game:GetService("TweenService") -- get service

local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
-- TweenInfo.new(number time, Enum easingStyle, Enum easingDirection, number repeatCount, bool reverses, number delayTime) -- not all of these are required

local Tween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(118, 109, 89)})
Tween:Play()
Tween.Completed:Wait() -- optional yield
3 Likes

Use TweenService to gradually affect the Ambient property of Lighting. See the examples on that page for inspiration.

Use TweenService