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

Why does my script pick the same random number every time it's run?

Every time I run my game, I want it to pick a random number.. But it picks the exact same number every time. How do I fix this?

math.randomseed(tick())

local replicatedStorage = game:GetService("ReplicatedStorage")
local tip = replicatedStorage:WaitForChild("TipValue")
local n

while true do
	
	n = math.random(1, 5)	
	
	if n == 1 then
		tip.Value = "Tip: Never stop moving!"
	end
	
	if n == 2 then
		tip.Value = "Tip: Don't let bombs corner you!"
	end
	a
	if n == 3 then
		tip.Value = "Tip: Stay as far away from bombs as possible!"
	end
	
	if n == 4 then
		tip.Value = "Tip: Don't get discouraged, you can do it!"
	end
	
	if n == 5 then
		tip.Value = "Tip: Chaos mode is hard, keep trying!"
	end
	
	wait(30)
end

3 comments

1

remove that 'a' on line 18, make sure the script is enabled too. I suggest making your loop last 1 second each wait so you can see this change faster and be sure it is random. Perhaps try making local n go inside of your while true loop.

0

If my suggestion works, please add [answered] to your title.

0

Ok, I did what you said, it picks random numbers each time it loads, but the first number that loads when I test the game is ALWAYS the same.

2 answers

First things first, IT IS RANDOM. Like, humans can see patterns but machines arent that advanced yet. Also, on line five, you did a variuble with no value. And on line eighteen, there is a "a". Ok that might be confusing but basiclly you did this on line eighteen.

a

So maybe just go and test some more.

2 comments

0

Yeah, I missed the A, I got rid of it. I set the variable to start with a number, still picks the exact same number each time.

0

I never said I will fix it, i explained why!

Try this:

while wait() do
	ns = {1,2,3,4,5}
	n = ns[math.random(1,#ns)]
	
	--Add the rest of the code here.
end

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