Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

math.random printing the same number forever?

Asked by 7 days ago

What I'm trying to do is when a player joins this game, it will roll a number between 1 and 3, If its 1 gui1 opens, and if its 2 or 3 gui2opens, my problem is the first player to join the game, lets say they get a 2 roll, everyone else gets a 2 role, not a 3 or 1. Even when the odds are raised to 1 and 10 it does the exact same thing. No errors. Besides that, the code works fine.

CODE:

local players = game:GetService("Players")

local num = math.random(1,10)



players.PlayerAdded:Connect(function(players)


    if num == 1 then

        game.StarterGui.gui1.Enabled = true
        print(num)
    else
        game.StarterGui.gui2.Enabled = true
        print(num)
    end



end)

thanks :)

1 answer

Log in to vote
0
Answered by 7 days ago

I'd advice that you move "local num = math.random(1,10)" inside of the PlayerAdded function, so it does MathRandom function every time the player is added. Therefore getting a new number.

0
Just move "local num = math.random(1,10)" under "players.PlayerAdded:Connect(function(players)" and it should work out for you. Unity_456 47 — 7d
0
forgot to mention, its in a script in ServerScriptService if that matters at all InfectedRythmCC 21 — 7d
0
That doesn't really matter. Just go on with what I described and it should work. Unity_456 47 — 7d
0
Eyyy ty fam :)! InfectedRythmCC 21 — 7d
Ad

Answer this question