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

How do I add more numbers in math.random?

Asked by 7 years ago

My question was probably not clear so I'll give a brief explanation.

I have a variable called "ctc" this is a random number between 1 and 250

when ctc is 3 it changes a value to "angel", how would I do this for multiple numbers?

like if I wanted 3 or 4 or 5 or 6 to also be "angel"?

local ctc= math.random(1,250)

local try = ReplicatedStorage.PlayerStats[id].Tries.Value
if try > 0 then
    if ctc == 3 then
        event:FireServer()


        script.Value.Value ="Angel"

        --script.Parent.Continue.Visible = true
    elseif

        ctc == 2 then
        event:FireServer()

        script.Value.Value = "Demon"

    --script.Parent.Continue.Visible = true
    elseif
        ctc== 1 then 
        event:FireServer()

        script.Value.Value = "Fallen-Angel"

        --script.Parent.Continue.Visible = true

    end
    elseif try <= 0 then
    script.Parent.Parent.Tries.Value = 0
    script.Parent.TextButton.Text = "No tries left!"

end

end

3 answers

Log in to vote
2
Answered by 7 years ago

You want to use the or gate, which returns true if one or more of the given parameters is true. For example, if you want to return 'angel' if ctc equals 3,4, or 5, then you would structure it like this:

local ctc = math.random(1,250)

if ctc == 3 or ctc == 4 or ctc == 5 then
    return "angel"
end

If you have a large group of numbers that ctc could equal, such as anything between 1 and 100, it is easier to structure it like this:

local ctc = math.random(1,250)

if ctc >= 1 or ctc <= 100 then
    return "angel"
end
0
For future reference, logical disjunctions and conjunctions of boolean expressions, in software programming, are called 'operators', not 'gates'. This is a trivial distinction, but often newbies read these answers and we don't want to introduce foreign terminology without reason. 'Gate' is usually reserved for circuits and hardware. duckwit 1404 — 7y
0
I've run into an issue, I have multiple values like 1,125 is angel and then 127,250 is fallen angel and 126 is demon. but I've gotten multiple values above 125 and it still says angel, what might the issue be? Fraxinus_Sanctus 38 — 7y
Ad
Log in to vote
-1
Answered by
gdunn2 54
7 years ago

or like this

if ctc >= 3 and <=5
0
This would syntax error. Instead, do if ctc >= 3 and ctc <= 5 then Kampfkarren 215 — 7y
0
oops thats what i meant :P sorry gdunn2 54 — 7y
Log in to vote
-2
Answered by
farrizbb 465 Moderation Voter
7 years ago
Edited 7 years ago

Use or i.e

if ctc == 3 or ctc == 4 or ctc == 5 then

Did it wrong before

0
This is not how "or" works. Programical 653 — 7y
0
Ya sure i'm pretty sure it is. farrizbb 465 — 7y
0
if the first statement is false(3) then it goes to the second(4) if thats false it goes to the next how is that not how or works :/ farrizbb 465 — 7y
0
This wouldn't work Kampfkarren 215 — 7y
View all comments (2 more)
0
Because you have to reference ctc each time. Azarth 3141 — 7y
0
Had it explained to me sos. farrizbb 465 — 7y

Answer this question