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

My randomizer works but I want it to have no duplicate numbers but I dont know where to start?

while true do
	local obbies = game.ServerStorage.Obbies:GetChildren()
	local random = math.random(1,#obbies)
	local chosen = game.ServerStorage:FindFirstChild(random)
	local clone = chosen:Clone()
	clone.Parent = workspace
	print(random)
	wait(30)
end

I need suggestions on what to do here.

1 answer

✓ Accepted answer

Hi SkatePro,

You could use a hashtable to keep track of all of the numbers that have already been randomly generated and then avoid those. It would end up looking like something along these lines:

local nums = {};

while true do
	local random_num = math.random(1, #obbies)

	while nums[random_num] do  -- Iterates until it can't find the number in the hashtable.
		wait();
		random_num = math.random(1, #obbies)
	end

	nums[random_num] = true; -- Set the number index to true in the table.
	wait(30);
end

##Hope I was able to help and have a great day/night.

Thanks,

Best regards,

Idealist Developer

2 comments

0

It does work but it does not repeat the random number generator.

0

Oh nevermind thanks

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