Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

4 comments

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.

0

Thank you, I am just barely starting out with scripting. Sorry if i sound like an idiot.

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.

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.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.