WeatherModule does nothing

I am working on a easy weathermodule with dynamic weather effects. The problem is, it just doesn’t work.
In the past when I was first testing it (when it didn’t check for the rain type) it worked fine, but now when I check it just doesn’t work? I honestly have no idea what is causing this.

Here is the modulescript inside replicatedstorage:

local Weather = {}

local TweenService = game:GetService("TweenService")
local RainModule = require(game.StarterPlayer.StarterPlayerScripts.RainScript.Rain)

AtmosphereTime = 4
RainStartTime = 7
RainStopTime = 7
RainSoundTime = 2

function Weather.RainStart(amount)
	if amount == "Light" then
		TweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(AtmosphereTime), {Density = 0.415}):Play()
		RainModule.SetIntensityRatio(0.250)
		RainModule.SetLightEmission(0.425)
		RainModule.SetLightInfluence(0.600)
		RainModule.SetSpeedRatio(0.550)
		RainModule.SetTransparency(0.275)
		RainModule.SetVolume(0.250)
		RainModule:Enable(TweenInfo.new(RainStartTime))
		print("Starting Light Rain!")
	elseif amount == "Medium" then
		TweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(AtmosphereTime), {Density = 0.477}):Play()
		RainModule.SetIntensityRatio(0.500)
		RainModule.SetLightEmission(0.775)
		RainModule.SetLightInfluence(0.675)
		RainModule.SetSpeedRatio(0.750)
		RainModule.SetTransparency(0.100)
		RainModule.SetVolume(0.400)
		RainModule:Enable(TweenInfo.new(RainStartTime))
		print("Starting Medium Rain!")
	elseif amount == "Heavy" then
		TweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(AtmosphereTime), {Density = 0.58}):Play()
		RainModule.SetIntensityRatio(0.750)
		RainModule.SetLightEmission(0.775)
		RainModule.SetLightInfluence(0.675)
		RainModule.SetSpeedRatio(1)
		RainModule.SetTransparency(0)
		RainModule.SetVolume(0.550)
		RainModule:Enable(TweenInfo.new(RainStartTime))
		print("Starting Heavy Rain!")
	elseif amount == "Extreme" then
		TweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(AtmosphereTime), {Density = 0.692}):Play()
		RainModule.SetIntensityRatio(1)
		RainModule.SetLightEmission(1)
		RainModule.SetLightInfluence(1)
		RainModule.SetSpeedRatio(1)
		RainModule.SetTransparency(0)
		RainModule.SetVolume(0.650)
		RainModule:Enable(TweenInfo.new(RainStartTime))
		print("Starting Extreme Rain!")
	end
end

function Weather.RainStop()
	RainModule:Disable(TweenInfo.new(RainStopTime))
end

return Weather

Here is the localscript inside of StarterCharacterScripts:

local WeatherHandler = require(game.ReplicatedStorage.Modules.WeatherHandler)

WeatherHandler:RainStop()

wait(3)

WeatherHandler:RainStart("Light")

wait(5)

WeatherHandler:RainStart("Medium")

wait(5)

WeatherHandler:RainStart("Heavy")

wait(5)

WeatherHandler:RainStart("Extreme")

The localscript is just for testing at the moment. I am not getting any errors. This is the module I am using for the rain

The problem is that you’re calling the functions using colon notation eg WeatherHandler:RainStart("Extreme"). This is the same as doing WeatherHandler.RainStart(WeatherHandler, "Extreme"), which is a no-op in that function. Change to WeatherHandler.RainStart("Extreme") and it’ll work just fine.

You can catch these errors by adding a call to error() when a function is given something it doesn’t recognize. Like this:


function Weather.RainStart(amount)
	if amount == "Light" then
		-- ...
	elseif amount == "Medium" then
		-- ...
	else
		-- If we got here, we got nonsense. Raise an error!
		error("Invalid rain amount:" .. tostring(amount)
	end
end
2 Likes

This seems to have fixed nothing happening, but now I get an error:

ReplicatedStorage.Modules.WeatherHandler:24: bad argument #1 to 'SetIntensityRatio' (number expected, got nil)

The rain now starts which means it does work, I guess I put a number in wrong? But in my script I put numbers in.

Might just want to double-check the RainModule API usage. I can’t really provide any feedback on that, since I don’t use it. Particularly the colon-vs-period member function calls.

1 Like

Can confirm, changing all of the ‘.’ to ‘:’ fixed the issue, thank you for your help!

1 Like