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

Why is random not being random? Why is this happening?

Asked by 8 years ago

Why is random not being random? Okay so this script is in a loop. It does a random outcome, but it just spams the same outcome it chose. For example lets say at the beginning of the game it chose "Outcome 2," now the script loops, so it goes back to the beginning, and it has to chose "Outcome 1-6," but it picks "Outcome 2 again." This repeats on the same server. However if it was a different server it would choose AT THE BEGINNING of the game a random outcome. Lets say this NEW server picks "Outcome 1," when the script loops, it spams that "Outcome 1." Why is this happening? Thanks!

01local randomDanger = math.random(1, 2)
02local randomSpeed = math.random(1, 3)
03 
04while true do
05    wait(1)
06    if randomDanger == 1 then
07        if randomSpeed == 1 then
08            --Outcome 1
09            wait(4)
10        elseif randomSpeed == 2 then
11            --Outcome 2
12            wait(4)
13        elseif randomSpeed == 3 then
14            --Outcome 3
15            wait(4)
View all 29 lines...
0
Yeah but why does it just spam the same outcome the whole time? If it is a different server it spams another outcome the whole time GatitosMansion 187 — 8y
0
I see why.Let me respond why. Reshiram110 147 — 8y
0
I responded with an answer.If it is the answer you were looking for,be sure to mark it as answered! Reshiram110 147 — 8y

1 answer

Log in to vote
4
Answered by 8 years ago

Hello.

The issue is,you are not re-assigning the value to have a random value inside the while loop.

Here is a fixed version:

01while true do
02local randomDanger = math.random(1, 2)
03local randomSpeed = math.random(1, 3)
04 
05    wait(1)
06    if randomDanger == 1 then
07        if randomSpeed == 1 then
08            --Outcome 1
09            wait(4)
10        elseif randomSpeed == 2 then
11            --Outcome 2
12            wait(4)
13        elseif randomSpeed == 3 then
14            --Outcome 3
15            wait(4)
View all 29 lines...
0
Oh that makes sense. Thanks! I uprooted too. GatitosMansion 187 — 8y
0
Thanks! Reshiram110 147 — 8y
Ad

Answer this question