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

How would I make it re-roll if its taken?

I want something like.

local hi = math.random(1,2)

if hi == 1 then

re does the math.random(1,2) until hi == 2 

1 answer

You'll want to use loops basically

local hi = math.random(1,2)

while hi ~= 2 do -- while hi is not equal to 2 loop
	wait()
	hi = math.random(1,2)
end

that will work if you only want 2 choices if you want more something like this will work

local taken = {} -- store all the used values
local hi = math.random(1,5) -- final unused value
local foundOne = false -- keep while loop going
while foundOne == false do
	wait()
	foundOne = true -- make true since it assumes it's not taken until proven wrong
	local hi = math.random(1,5) -- change hi to new value
	for i = 1,#taken do -- loop through all used values
		if taken[i] == hi then -- value is taken
			foundOne = false -- continue loop
		end
	end
end
table.insert(taken,hi) -- add value to used list

1 comment

0

sorry if there's some errors i'm not in studio so I can't confirm everything works 100% but you get the gist of what needs to be done

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