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

How Can I make a Random Picker actually Decide Randomly(math.random problems)?

So I use math.random to pick out one player from the entire server to be chosen as a monster. Simple, right? However, the problem is that sometimes that same player gets picked again. He can be picked up to 10 times in a row before the picker chooses another person, which is a huge problem. How can I go about making a truly random picker, and make sure that the person who was just picked cannot be chosen again until at least 2 rounds later?

My current script (functional, but problem is stated above):

-- this function is fired every time a new round starts.
function chooseBeast()
	local plrs = game.Players:GetPlayers()
	local eligibleplrs = {}
	for _,v in pairs(plrs) do
		if v:FindFirstChild("AFK") and v.AFK.Value == false then
			table.insert(eligibleplrs, v)
		end
	end
	local randteam = eligibleplrs[math.random(1, #eligibleplrs)] --<- choose monster HERE --
end
-- this is a simplified version of my script btw, above this comment is where my problem arises.

while wait(120) do
	resetEverything()
	-- intermission
	wait(30)
	chooseBeast()
	LoadMap(math.random(1, 10)
end

3 comments

0

I have this problem too. It is just Roblox, you can't rly fix it...

0

That will happen, you just need more players in your game.

0

I had around 5 players at one time with the same problem, idk what to do honestly. I've seen other successful games that seem to have solved this problem.

1 answer

You can change the seed of math.random by doing math.randomseed(number). For the best results, the number should be something that is always different, such as the return value of tick() or time()

Or you can stop using math.random at all and use the Random class

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