Change weather server side only fires once

Hi,

I know that this is not ideal but I want to do it anyway.

This works fine when I execute it server side but I can only fire it once which is duo to the loop and the wait I guess, but is there a way to cancel it out and execute a new thread? I tried to use the native CleanAllWeatherModules I think its called, but that didnt work:

RegisterNetEvent("setWeather")
AddEventHandler("setWeather", function(weathertype)
	Citizen.CreateThread(function()
		while true do
			SetWeatherTypePersist(weathertype)
			SetWeatherTypeNowPersist(weathertype)
			SetWeatherTypeNow(weathertype)
			SetOverrideWeather(weathertype)
			Citizen.Wait(1)
		end
	end)
end)
Added code tags.

Have the thread outside of the event, referencing a global variable, and update global variable in the event handler.

@leaf Sound’s easy

How could it look like?

local updateSeason = "EXTRASUNNY"

RegisterNetEvent("setSeason")
AddEventHandler("setSeason", function(weathertype)
	updateSeason = weathertype
end)

Citizen.CreateThread(function()
		while true do
                        Citizen.Wait(1)
			SetWeatherTypePersist(updateSeason)
			SetWeatherTypeNowPersist(updateSeason)
			SetWeatherTypeNow(updateSeason)
			SetOverrideWeather(updateSeason)			
		end
end)

@leaf Ping!, example please.