Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a script more smoothly?

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

1 comment

0

Use a for loop

2 answers

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

3 comments

0

It only makes the game brighter

0

then remove line six

0

It still makes it bright as hell

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.