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

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

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.

1 comment

2 answers

✓ Accepted answer
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))

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

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