{SOLVED} Attempt to compare number <= nil?

Hello,

I am trying to make a dialogue skip where if the player is 50 counts in, they can skip it by clicking the mouse; Somehow this simple concept resulted with an error: attempt to compare number <= nil.
Whenever I do == it does not error but if I put <= or >= it errors.
Here’s the part of the script that errors:

local function typewrite(object,text,length)
		for i = 1,#text,1 do
			object.Text = string.sub(text,1,i)
			task.wait(length)
			txtam = i
			print(txtam)
		end
		task.wait(6)
		object.Text = ""
		GUI.Enabled = false
	end
	 if txtam >= 50 then -- error line
		print("50 reached/over")
		UIS.InputBegan:Connect(function(i,busy)
			if busy then return end
			if i.UserInputType == Enum.UserInputType.MouseButton1 and GUI.Enabled == true then
				speed = 0.01
				typewrite(DIALOGUE,DIALOGUETEXT,speed)
			end
		end)
	end

Note: I have not included the full script, you can ask me for the full script in the replies.

what is txtam? That is not mentioned anywhere else in the script. You are receiving this error because txtam is supposedly nil.

1 Like

It’s defined at the beginning of the script as local txtam, I have not included the full script.

You declare txtam here but the function doesn’t run by the time the line with the error runs. Why is the if statement outside of the function?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.