How to put math.random to switch between 2 seconds or 2.5 seconds or 2.75 seconds or 3 seconds in wait?
light=script.Parent.SpotLight r=math.random(2,2.5),math.random(2.75,3) rr=math.random(.3,.35),math.random(.4,.45),math.random(.5,.55)
The Output does "0 2 0 2 0 2 0 2 0 2" ECT.. ex: wait(r) --waits 2 or 2.5 or 2.75 or 3 seconds (random) How would I be able to do this without it doing the Output provided above? Help would be appreciated!
math.random has two modes, only: integers and percentage
The integer mode will only give you integers (which is why you're only getting 0 and 2), and is used by putting in numbers into the function.
The percentage mode is simply: math.random()
and will return a randomized, fractional number between 0 and 1, inclusive (although 0 and 1 are rare in and of themselves).
If you want to choose between 4 explicit steps randomly, use a table:
waits = {2, 2.5, 2.75, 3} local r = waits[math.random(1, 4)] print(r)
waits={0.35, 0.65, 1.35, 1.8} waitss={0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5} r = waits[math.random(1, 4)] rr = waitss[math.random(1, 8)]
Output: 1.35 0.4 1.35 0.4 1.35 0.4 1.35 0.4 ECT... It seems that It's picking 2 random numbers from the tables to start with, then keeps using them over and over and over again.. How would I fix this? Full code:
light=script.Parent.light.SpotLight baselight=script.Parent.light waits={.35,.65,1.35,1.8} waitss={.15,.2,.25,.3,.35,.4,.45,.5} r = waits[math.random(1,4)] rr = waitss[math.random(1,8)] while true do print(r) print(rr) wait(r) light.Color=Color3.new(120,120,120) light.Angle=60 light.Range=15 light.Brightness=1 baselight.BrickColor=BrickColor.new("Mid gray") wait(rr) light.Color=Color3.new(255,255,255) baselight.BrickColor=BrickColor.new("Light stone grey gray") light.Angle=71.5 light.Range=20 light.Brightness=3 end