How can one make a math.random number in a while loop?

I’m trying to make a lighting graphic using the Atmosphere properties.

local clock = math.random(7.5, 20)

while true do
	wait(clock)
	print(clock)
	game.Lighting.Atmosphere.Glare = 7.5
	wait(.025)
	game.Lighting.Atmosphere.Glare = 0
	wait(.025)
	game.Lighting.Atmosphere.Glare = 7.5
	wait(.025)
	game.Lighting.Atmosphere.Glare = 0
	wait(.05)
	game.Lighting.Atmosphere.Glare = 10
	TS:Create(game.Lighting.Atmosphere, TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Glare = 0}):Play()
	wait(1.5)
	script.thundernoise:Play()
end

But the output keeps saying

8 (x5)

Any help regarding this? How can a random number be generated each loop? Does the variable in any way helping to prevent the randomization?

1 Like

You just need to move the local clock = math.random(7.5, 20) inside of the loop if you want to generate a new random number each time to loop repeats.

2 Likes

Thank you! The variable was outside the while loop and just generated a number and so that may have caused it.