I have a script that when fired, makes a certain GUI visible. The script does what its told, and the "Visible" boxs becomes Checked when the script fires, yet the GUI still remains invisible
01 | cam = game.Workspace.cam |
02 |
03 | game.StarterGui.Cameras:WaitForChild( "static" ) |
04 |
05 | cam.Changed:connect( function () |
06 | if cam.Value ~ = 0 then |
07 | game.StarterGui.Cameras.static.Visible = true |
08 | local m = math.random(. 01 ,. 07 ) |
09 | while true do |
10 | wait(. 1 ) |
11 | game.StarterGui.Cameras.static.ImageTransparency = m |
12 | end |
13 | end |
14 | end ) |
Help?
math.random can only make integer
1 | --[[line 08]] local m = math.random( 1 , 7 )/ 10 |
math.random(low, high)
requires that low
and high
be integers. If they're not, it just rounds1 them. It then picks an integer between low
and high
.
Much of the time, that's what you want -- it makes it easy to pick things from a list, etc.
If you want to have non-integer random numbers, you could just scale down, e.g.
1 | math.random( 1 , 7 ) / 100 |
2 | -- pick one of 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07 |
However, this is not necessarily clear, and it can't pick any number, it can only pick a handful. You could add more by tacking on more 0s...
1 | math.random( 100 , 700 ) / 10000 |
but that's obviously not elegant.
If you want any random number, you should use math.random()
which returns a random number between 0
and 1
(include 0
, but not including 1
). Thus to get a range from low
to high
, it looks something like
1 | low + math.random() * (high - low) |
In your case, that's
1 | 0.01 + math.random() * 0.06 |
It looks like it's round-towards-even, though that might not be platform independent ↩