Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

math.random printing the same number forever?

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

✓ Accepted answer

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.

4 comments

0

Just move "local num = math.random(1,10)" under "players.PlayerAdded:Connect(function(players)" and it should work out for you.

0

forgot to mention, its in a script in ServerScriptService if that matters at all

0

That doesn't really matter. Just go on with what I described and it should work.

0

Eyyy ty fam :)!

This discussion is preserved as it was. New answers, comments, and votes are closed.