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

Confused with how math random works, can I get help?

Asked by 6 years ago

So, I know math random selects a random number. But can you set it to select a number within a range you assign? Something like

math random 10 - 20

Sorry about my LUA, I'm still learning! Just need this question answered, because i'm confused.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
math.random(10,20)

gets a random number from 10 - 20 as you said.

Remember to use . and ()

if this doesn't work then open the output and type this in:

print(math.random(10,20))
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Example

Baseplate = game.Workspace.BasePlate

while true do
wait(1)
ColorstoChooseFrom = math.random(1,3)

if ColorstoChooseFrom == 1 then
Baseplate.BrickColor = BrickColor.new("Red")
end

if ColorstoChooseFrom == 2 then
Baseplate.BrickColor = BrickColor.new("Blue")
end

if ColorstoChooseFrom == 3 then
Baseplate.BrickColor = BrickColor.new("Green")
 end
end

Thats An Exapmple on How Math.Random Works

Answer this question