Help with adding Numbers to Text..?

I am currently making a system were you have to guess if something is true/false. I am trying to make it so if you get an answer wrong then it will add a number each time you get one wrong and will keep adding up until 3/3. I’ve tried searching the developer hub, but have had no luck finding how…

local function onFocused()
	textBox.BackgroundColor3 = colornormal
end

local function onFocusLost(enterPressed, inputObject)
	if enterPressed then
		local guess = textBox.Text
		if guess == correctanswer then
			textBox.Text = "True"
			textBox.BackgroundColor3 = colorcorrect
			wait(2)
			textBox.Text = ""
			textBox.BackgroundColor3 = colornormal
		else
			textBox.Text = "False"
			textBox.BackgroundColor3 = colorincorrect
			wait(2)
			textBox.Text = ""
			textBox.BackgroundColor3 = colornormal
		end
	else

		textBox.Text = ""
		textBox.BackgroundColor3 = colornormal
	end
end

textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

This should actually be quite simple. You just need to add some variables and check if the incorrect answers have exceeded your threshold. Not exactly sure if this will work with your exact set up but it should look something like this:

local currentIncorrectAnswers = 0
local maxIncorrectAnswers = 3

local function onFocused()
	textBox.BackgroundColor3 = colornormal
end

local function onFocusLost(enterPressed, inputObject)
	if enterPressed then
		local guess = textBox.Text
		if guess == correctanswer then
			textBox.Text = "True"
			textBox.BackgroundColor3 = colorcorrect
			wait(2)
			textBox.Text = ""
			textBox.BackgroundColor3 = colornormal
		else
			textBox.Text = "False"
			textBox.BackgroundColor3 = colorincorrect
			wait(2)
			textBox.Text = ""
			textBox.BackgroundColor3 = colornormal
			currentIncorrectAnswers = currentIncorrectAnswers + 1 ---Adding to the incorrect value each time they get one wrong
			if currentIncorrectAnswers == maxIncorrectAnswers then 
				--Do whatever you want to do once they've hit the threshold 
			end
		end
	else

		textBox.Text = ""
		textBox.BackgroundColor3 = colornormal
	end
end

textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)
1 Like