How would I make dynamic fog?

local fognum = math.random(100,250)
	print(fognum)
	if fog >= fognum then
		repeat
			fog = fog -1
			wait(1)
		until fog == fognum
	elseif fog <= fognum then
		repeat
			fog = fog +1
			wait(1)
		until fog == fognum
	end

Right now this does nothing, but what I want to do is if the random generated number is greater than the fog already in the game, I want it to increase the fog in the game until it is the same as the the generated number, if the generated number is smaller than the fog already in the game, I want the fog (in-game) to decrease until it is the same as the generated number.

local fognum = math.random(100,250)
	print(fognum)
	local frn = game.Lighting.FogEnd
	if fog >= fognum then
		repeat
			game.Lighting.FogEnd = game.Lighting.FogEnd - .01
			wait(.01)
		until fog <= fognum
	elseif fog <= fognum then
		repeat
			game.Lighting.FogEnd = game.Lighting.FogEnd + .01
			wait(.01)
		until fog >= fognum
	end

Note to self: Don’t use variables for in-game values

2 Likes