Somehow making normal numbers work with strings

I’m making a verification system, and I basically asking: Choose number: Three
And then having 4 numbers that display like this:

1 3
8 2

When you choose number three, you can move on.
But i’ve ran into a problem, I have a function that always returns different numbers than the others when its called, but I can’t get it to work with numbers that are spelled out. Now, I would use something like this: Choose number: 3. I but I bet this can be bypassed very easily. So please, tell me how if there is a way.

The entire script

local numbers = {1,2,3,4,5,6,7,8,9,0}
local numberNames = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Zero"}
local RandomButton = {1,2,3,4}
local generatedNumbers = {}
local QuestionLabel = script.Parent.QuestionLabel
local CorrectNum = script.Parent.CorrectNum
local t1 = script.Parent.t1
local t2 = script.Parent.t2
local t3 = script.Parent.t3
local t4 = script.Parent.t4
local QuestionLabelAnswer
local Correct

local function uniquePseudoRandomGenerator(lower : number, upper : number) : number
	if upper - lower + 1 == #generatedNumbers then print("err") end
	local randomNumber
	repeat
		randomNumber = math.random(lower, upper)
	until not table.find(generatedNumbers, randomNumber)
	table.insert(generatedNumbers, randomNumber)
	return randomNumber
end

local function RandomVerify()
	
	task.wait(0.42)
	
	CorrectNum.Value = uniquePseudoRandomGenerator(1,#numberNames)
	QuestionLabel.Text = "Choose number: "..CorrectNum.Value

	if CorrectNum.Value == "One" then
		QuestionLabelAnswer = 1
	elseif CorrectNum.Value == "Two" then
		QuestionLabelAnswer = 2
	elseif CorrectNum.Value == "Three" then
		QuestionLabelAnswer = 3
	elseif CorrectNum.Value == "Four" then
		QuestionLabelAnswer = 4
	elseif CorrectNum.Value == "Five" then
		QuestionLabelAnswer = 5
	elseif CorrectNum.Value == "Six" then
		QuestionLabelAnswer = 6
	elseif CorrectNum.Value == "Seven" then
		QuestionLabelAnswer = 7
	elseif CorrectNum.Value == "Eight" then
		QuestionLabelAnswer = 8
	elseif CorrectNum.Value == "Nine" then
		QuestionLabelAnswer = 9
	elseif CorrectNum.Value == "Zero" then
		QuestionLabelAnswer = 0
	end

	Correct = RandomButton[math.random(1,#RandomButton)]

	if Correct == 1 then
		t1.IsCorrect.Value = true
		t1.Number.Text = QuestionLabelAnswer
	elseif Correct == 2 then
		t2.IsCorrect.Value = true
		t2.Number.Text = QuestionLabelAnswer
	elseif Correct == 3 then
		t3.IsCorrect.Value = true
		t3.Number.Text = QuestionLabelAnswer
	elseif Correct == 4 then
		t4.IsCorrect.Value = true
		t4.Number.Text = QuestionLabelAnswer
	end
for i,v in pairs(script.Parent:GetChildren()) do
	if v.Name == "t1" or v.Name == "t2" or v.Name == "t3" or v.Name == "t4" then
			if v:WaitForChild("IsCorrect").Value ~= true then
				v:WaitForChild("Number").Text = uniquePseudoRandomGenerator(1,#numbers)
			end
		end
	end
end



t1.MouseButton1Up:Connect(function()
	if t1.IsCorrect.Value == true then
		task.wait(1)
		t1.IsCorrect.Value = false
		RandomVerify()
	end
end)

t2.MouseButton1Up:Connect(function()
	if t2.IsCorrect.Value == true then
		task.wait(1)
		t2.IsCorrect.Value = false
		RandomVerify()
	end
end)

t3.MouseButton1Up:Connect(function()
	if t3.IsCorrect.Value == true then
		task.wait(1)
		t3.IsCorrect.Value = false
		RandomVerify()
	end
end)

t4.MouseButton1Up:Connect(function()
	if t4.IsCorrect.Value == true then
		task.wait(1)
		t4.IsCorrect.Value = false
		RandomVerify()
	end
end)

RandomVerify()

Sorry what is your issue? I don’t really understand the description you left.

I have 2 tables, one with numbers, and strings for the numbers. I can’t figure out how to make them both work with this function.

So you want it so that what ever number you get you can convert it to a string (as an example you get the number 1 so it would show one)?

Actually the opposite, that’s why this is kind of complicated.

Can you not just have the numbers it could possibly be inside of a dictionary and then it just checks for the number? (as an example you have the string one so you check the dictionary to find the name of the value).

More on dictionary’s can be found here: https://education.roblox.com/en-us/resources/intro-to-dictionaries---series

It won’t let me use numbers for it

if you want to check for string numbers, you can do this

if table.find(numberNames, numberName) == number  then

end

or if you want to take a string number

local numberName = numberNames[number]

if you put invalid keys in a table, you would need to quote it and enclose the key in a square bracket []

local table = {
	["1"] = 1337,
	["2"] = 69,
	["3"] = 420
}

and also, tostring() and tonumber() exists

I made a dictionary, how would incorporate this with my function:

Dictionary:

local numberNames = {
	["1"] = "One",
	["2"] = "Two",
	["3"] = "Three",
	["4"] = "Four",
	["5"] = "Five",
	["6"] = "Six",
	["7"] = "Seven",
	["8"] = "Eight",
	["9"] = "Nine",
	["0"] = "Zero"
}

Function:

local function uniquePseudoRandomGenerator(lower : number, upper : number) : number
	if upper - lower + 1 == #generatedNumbers then print("err") end
	local randomNumber
	repeat
		randomNumber = math.random(lower, upper)
	until not table.find(generatedNumbers, randomNumber)
	table.insert(generatedNumbers, randomNumber)
	return randomNumber
end

you use tostring(number) for that

Could you show me a code example with my function, please? Sorry I’m not very good with math in lua. :sweat:

i mean like, after you return the number, you do tostring(number)
example:

local numberString = tostring(uniquePseudoRandomGenerator(0,9))
local numberName = numberNames[numberString]

I tried your method, it picks a random number on run, then does this:

Then if you choose the number (5) it says its correct. Then the number just changes to a random spot after you get one right. It also sometimes displays multiple numbers like this: