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!

local randomDanger = math.random(1, 2)
local randomSpeed = math.random(1, 3)

while true do
    wait(1)
    if randomDanger == 1 then
        if randomSpeed == 1 then
            --Outcome 1
            wait(4)
        elseif randomSpeed == 2 then
            --Outcome 2
            wait(4)
        elseif randomSpeed == 3 then
            --Outcome 3
            wait(4)
        end
    elseif randomDanger == 2 then
        if randomSpeed == 1 then
            --Outcome 4
            wait(4)
        elseif randomSpeed == 2 then
            --Outcome 5
            wait(4)
        elseif randomSpeed == 3 then
            --Outcome 6
            wait(4)
        end
    end
end
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:


while true do local randomDanger = math.random(1, 2) local randomSpeed = math.random(1, 3) wait(1) if randomDanger == 1 then if randomSpeed == 1 then --Outcome 1 wait(4) elseif randomSpeed == 2 then --Outcome 2 wait(4) elseif randomSpeed == 3 then --Outcome 3 wait(4) end elseif randomDanger == 2 then if randomSpeed == 1 then --Outcome 4 wait(4) elseif randomSpeed == 2 then --Outcome 5 wait(4) elseif randomSpeed == 3 then --Outcome 6 wait(4) end end end
0
Oh that makes sense. Thanks! I uprooted too. GatitosMansion 187 — 8y
0
Thanks! Reshiram110 147 — 8y
Ad

Answer this question