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

How can I give a variable a equal to a random number?

Asked by 5 years ago

I tried all that I know. I know what math.random is but I do not know how to make it go to a variable. Here is my attempt

while true do

wait(.1)

MyNum = math.random

if MyNum == 1 then

0
what do you mean... local MyNum = math.random(1,100) if MyNum == 30 then --code end MyNum is the random variable, to simply transfer it say, local NewMyNum = MyNum, I really do not understand what you are thinking right now. greatneil80 2647 — 5y
0
Thank you, I am just barely starting out with scripting. Sorry if i sound like an idiot. 50ShadesofLamps 5 — 5y
0
Tip for writing questions on here, it's recommended to put code in the 'Code Block' (The <> at the top of the screen when editing the question) format, it makes it easier to traverse the code. Also good luck on programming. ninja_eaglegamer 61 — 5y
0
Tip for writing questions on here, it's recommended to put code in the 'Code Block' (The <> at the top of the screen when editing the question) format, it makes it easier to traverse the code. Also good luck on programming. ninja_eaglegamer 61 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well first of all the number range for

math.random

is -infinity to infinity so the chances of you getting 1 in that large amount of numbers are slim to none so what you could do is

while wait(3) do -- every 3 seconds
    local Var = math.random(-5,5) --setting range to be -5 through 5
    if Var == 1 then -- which is 1/11 chances of getting a 1 but you get the point
        print("Var = "..Var)
    else
        print("No")
    end
end

Random Number Generation Here

Ad

Answer this question