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

Changes background transparency to 0 instead of 0.1 - 0.9?

Asked by 8 years ago

I am trying to make this script change the BackgroundTransparency of a frame to a random number between 0.1 to 0.9 but it ends up setting it as 0. Can anyone tell me how to make this work besides having to do.

if math == 1 then
    script.Parent.BackgroundTransparency = 0.1
end

Here is the script:

local math = math.random(1,9)
script.Parent.BackgroundTransparency = 0.,math

2 answers

Log in to vote
1
Answered by
davness 376 Moderation Voter
8 years ago

just divide the number by 10!

script.Parent.BackgroundTransparency = math.random(1,9)/10 -- will generate a number between 0.1 and 0.9
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

Note: You should never overwrite standard roblox variables like math, pick a different variable name

You need to set the BackgroundTransparency to your variable on line 1 divided by 10!

local random = math.random(1,9) --rename your variable
script.Parent.BackgroundTransparency = random/10

Answer this question