Making this RainCycle script work properly (TweenService)

Hai, i’ve been trying to add tweenservice to this script, its supposed to create a raincycle. I wanted the TweenService to make the effects such as colorcorrection, atmosphere or depthoffield to be enabled really smoothly. However, the script seems to be bugging and not working properly, how do i fix this?

The Script:

--locals
local Brightness = game.Lighting.Brightness
local DepthOfFieldValue = game.Lighting.DepthOfField2.FarIntensity
local ColorCorrectionBrightness = game.Lighting.ColorCorrection2.Brightness
local ColorCorrectionContrast = game.Lighting.ColorCorrection2.Contrast
local ColorCorrectionSaturation = game.Lighting.ColorCorrection2.Saturation
local AtmosphereDensity = game.Lighting.Atmosphere.Density
local RainStraightRate = script.Parent.Parent.Parent.Parent.Workspace.Camera.__RainEmitter.RainStraight.Rate
local RainTopDownRate = script.Parent.Parent.Parent.Parent.Workspace.Camera.__RainEmitter.RainTopDown.Rate
local RainVolume = script.Parent.Parent.Parent.Parent.SoundService.__RainSoundGroup.Volume
local RainScriptEnabled = script.Parent.RainScript.Enabled
local TweenService = game:GetService('TweenService')
local lighting = game.Lighting


function RainCycle()
	-- Start with default values
	Brightness = 6
    DepthOfFieldValue = 0
	ColorCorrectionBrightness = 0
    ColorCorrectionContrast = 0
	ColorCorrectionSaturation = 0
	AtmosphereDensity = 0.33
	RainStraightRate = 0
	RainTopDownRate = 0
	RainVolume = 0

	-- This is what we want to happen during/after tween
	
	Brightness = 1
	DepthOfFieldValue = 0.05
	ColorCorrectionBrightness = 0.1
	ColorCorrectionContrast = 0.1
	ColorCorrectionSaturation = 0.5
	AtmosphereDensity = 0.45
	RainStraightRate = 400
	RainTopDownRate = 400
	RainVolume = 20
	

	-- Create tween info
	local tweenInfo = TweenInfo.new(30) -- Change 1.5 to however long you want the tween to take

	-- Create tween
	local tween =  tweenService:Create(Lighting, tweenInfo, tweenValues)
	tween:Play() -- Play tween
	end


while true do
	if (math.random(1,60) == 2) then RainCycle() end --Change this to a higher number and it won't start raining as likely, for an example "(1,200) == 2)"
	wait(2)
	
end

All locals should be working.

Your first issue is here:

local tween =  tweenService:Create(Lighting, tweenInfo, tweenValues)

It should be:

	local tween =  TweenService:Create(lighting, tweenInfo, tweenValues)

These variables weren’t referenced correctly. Not to mention the fact that twen values aren’t defined in the script, so I can’t even debug this properly.

1 Like

I cleaned up your code so u better shine my shoe… jk here u go

local TweenService = game:GetService('TweenService')
local Lighting = game:GetService('Lighting')

local SomeStupidPath = script.Parent.Parent.Parent.Parent

local Brightness = Lighting.Brightness
local DepthOfFieldValue = Lighting.DepthOfField2.FarIntensity

local ColorCorrectionBrightness = Lighting.ColorCorrection2.Brightness
local ColorCorrectionContrast = Lighting.ColorCorrection2.Contrast
local ColorCorrectionSaturation = Lighting.ColorCorrection2.Saturation

local AtmosphereDensity = Lighting.Atmosphere.Density

local RainStraightRate = SomeStupidPath.Workspace.Camera.__RainEmitter.RainStraight.Rate
local RainTopDownRate = SomeStupidPath.Parent.Workspace.Camera.__RainEmitter.RainTopDown.Rate
local RainVolume = SomeStupidPath.SoundService.__RainSoundGroup.Volume
local RainScriptEnabled = script.Parent.RainScript.Enabled

local RainConfig = {
	CanRain = true
}


function RainCycle()
	RainConfig.CanRain = nil
	
	Brightness = 6
	DepthOfFieldValue = 0
	ColorCorrectionBrightness = 0
	ColorCorrectionContrast = 0
	ColorCorrectionSaturation = 0
	AtmosphereDensity = 0.33
	RainStraightRate = 0
	RainTopDownRate = 0
	RainVolume = 0

	Brightness = 1
	DepthOfFieldValue = 0.05
	ColorCorrectionBrightness = 0.1
	ColorCorrectionContrast = 0.1
	ColorCorrectionSaturation = 0.5
	AtmosphereDensity = 0.45
	RainStraightRate = 400
	RainTopDownRate = 400
	RainVolume = 20
	

	local tween = TweenService:Create(Lighting, 
		TweenInfo.new(30), {
			Brightness = Brightness,
			DepthOfFieldValue = DepthOfFieldValue,
			ColorCorrectionBrightness = ColorCorrectionBrightness,
			ColorCorrectionContrast = ColorCorrectionContrast,
			ColorCorrectionSaturation = ColorCorrectionSaturation,
			AtmosphereDensity = AtmosphereDensity,
			RainStraightRate = RainStraightRate,
			RainTopDownRate = RainTopDownRate,
			RainVolume = RainVolume
		}
	)
	
	tween:Play()
	tween.Completed:Wait()
	
	RainConfig.CanRain = true
end

while task.wait(2) do
	if (math.random(1,60) == 2) and RainConfig.CanRain then 
		RainCycle()
	end
end
1 Like

theres a problem, it starts raining(without the lighting changes) as soon as the player joins

I have no clue where your variables are leading but check because I don’t have access to the game they might be wrong, as for the rain starting right away, are u sure ur not calling the func urself from somewhere else?

1 Like

ill see, thx sm already! is there anywhere i can friend and message u?


This is what the script looks like btw, its from a rain plugin.