Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a script more smoothly?

Asked by 5 years ago

Hello, I have this script, which changes the Brightness, Fog and OutDoorAmbient of the game when you touch it.

My problem is: It instantly switches, how do I make it go more smoothly?

local lighting = game.Lighting

script.Parent.Touched:Connect(function()

    lighting.Brightness = 0
    lighting.FogStart = 50
    lighting.FogColor = Color3.new(0,0,0)
    lighting.OutdoorAmbient = Color3.new(0,0,0)


end)

It's a very simple script but I don't know how to do this kind of stuff. Thanks for your help

0
Use a for loop User#19524 175 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

you could use a loop to gradually change their properties

local lighting = game.Lighting

script.Parent.Touched:Connect(function()
    local num1 = 0
    while num1 <= 50 do
        lighting.Brightness = lighting.Brightness -1
        lighting.FogStart = lighting.FogStart + 1
        lighting.FogColor = Color3.new(0+1, 0+1, 0+1)
        lighting.OutdoorAmbient = Color3.new(0+1, 0+1, 0+1)

        num1 = num1 + 1
        wait(0.1)
    end
end)

For each property you would put the number they started at and then add or subtract 1 depending on what number you would want to end up on

you could also use a for loop

0
It only makes the game brighter Theroofypidgeot 21 — 5y
0
then remove line six greatneil80 2647 — 5y
0
It still makes it bright as hell Theroofypidgeot 21 — 5y
Ad
Log in to vote
0
Answered by
yellp1 193
5 years ago
Edited 5 years ago

Sorry for my sloppy code! To change the speed go to Speed and change it to the time you want (In seconds)!

local lighting = game.Lighting
local Debounce = false
local Speed = 1

local function Tween(t,s,d,p,o)
    return game:GetService("TweenService"):Create(o,TweenInfo.new(t,Enum.EasingStyle[s],Enum.EasingDirection[d]),p)
end

script.Parent.Touched:Connect(function()
    if not Debounce then
        Debounce = true
        Tween(Speed,"Sine","InOut",{Brightness = 0,FogStart = 50,FogColor = Color3.fromRGB(0,0,0),OutdoorAmbient = Color3.fromRGB(0,0,0)},lighting):Play()
    end
end)

Answer this question