Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Weird GUI problem?

Asked by 9 years ago

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

cam = game.Workspace.cam

game.StarterGui.Cameras:WaitForChild("static")

cam.Changed:connect(function()
    if cam.Value ~= 0 then
        game.StarterGui.Cameras.static.Visible = true
        local m = math.random(.01,.07)
        while true do
            wait(.1)
            game.StarterGui.Cameras.static.ImageTransparency = m
        end
    end
end)

Help?

0
Are you trying to make the gui smoothly transistion from invisible to visible? math.random() will make it flash.. Nickoakz 231 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

math.random can only make integer

--[[line 08]]  local m=math.random(1,7)/10
1
/100 YellowoTide 1992 — 9y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

math.random(1, 7) / 100
-- 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...

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

low + math.random() * (high - low)

In your case, that's

0.01 + math.random() * 0.06

  1. It looks like it's round-towards-even, though that might not be platform independent 

Answer this question