Generating Numbers

Using Math.Random

by angelux079

Author Avatar

Math.Random is a function that generates a number from Math.Random(a,b) if a = 10 and b = 20 it would generate a number from 10-20

You can use variables to function Math.Random, in the script below it will show how to use it

local a = 10 --The number 1 that goes in Math.random(a,b)
local b = 20 --The number 2 that goes in Math.random(a,b)

math.random(a,b) --Using variables we can transfer the values into the function

--------------------------------------------------------------------------------

--Example Script

local c = 1
local d = 10


local Generated_Number = 0

script.Parent.Button.MouseButton1Click:Connect(function()--When a button is pressed functions the code below

if Generated_Number == 0 then

Generated_Number = math.random(c,d)

elseif Generated_Number ~= 0 then

Generated_Number = math.random(c,d)

end

script.Parent.Button.Text = Generated_Number

end)

View in-game to comment, award, and more!