Script not working

how can I make this script affect all of the stations at once? they are all under a folder named Weather Stations and have a gui and textlabel in them

local function updateWeather(station)
	local surfaceGui = station.SurfaceGui
	if surfaceGui and surfaceGui:FindFirstChild("TextLabel") then
		local chance = math.random(1, 3)
		if chance == 3 then
			local chance2 = math.random(1, 2)
			if chance2 == 1 then
				surfaceGui.TextLabel.Text = "Weather Update: Fog Incoming"
				task.wait(math.random(5, 13))
				local fog = game.ServerStorage["Foggy Conditions"]:Clone()
				surfaceGui.TextLabel.Text = "Weather: Fog"
				fog.Density = 0.41
				fog.Parent = game.Lighting
				task.wait(math.random(230, 450))
				fog:Destroy()
				surfaceGui.TextLabel.Text = "Weather: Clear"
			elseif chance2 == 2 then
				surfaceGui.TextLabel.Text = "Weather Update: Dense Fog Incoming"
				task.wait(math.random(5, 13))
				local fog = game.ServerStorage["Foggy Conditions"]:Clone()
				surfaceGui.TextLabel.Text = "Weather: Dense Fog"
				fog.Density = 0.6
				fog.Parent = game.Lighting
				task.wait(math.random(230, 450))
				fog:Destroy()
				surfaceGui.TextLabel.Text = "Weather: Clear"
			end
		end
	end
end

local function manageWeatherStations()
	local weatherStations = workspace["Weather Stations"]:GetChildren()
	while true do
		task.wait(math.random(1.6, 3))
		for _, station in ipairs(weatherStations) do
			updateWeather(station)
		end
	end
end

manageWeatherStations()
2 Likes

try this:

local function manageWeatherStations()
	local weatherStations = workspace["Weather Stations"]:GetChildren()
	while true do
		for _, station in ipairs(weatherStations) do
			updateWeather(station)
		end
		task.wait(math.random(1.6, 3))
	end
end
1 Like

It doesn’t seem to work or print any errors, thank you for the help though
I just got it fixed

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.