How can I make a simple random script. For example I have a value and I want to change the value to either 1 or 2 and to do that you have a 50/50 change for each how would I do that?
How would I use that as a random if statement? such as 50 percent to do something and 50 percent to do something else.
if math.random(1, 2) == 1 then
-- code
else
-- code
end
1 Like
If you wanted to have 3 options, you could include an elseif
as well, but you would have to store the random in a variable like so:
local chance = math.random(1, 3)
if chance == 1 then
-- code
elseif chance == 2 then
-- code
else
-- code
end
1 Like