Is there a way to use "or" in scripting?

Is there a way in scripting where you can say or? An example for what I mean is:

if 1 > 0 OR 3>2 then...

something like that. How would I do it in my example?

1 Like

That’s exactly how to do it.
if x >= to y or y<3 then... checks if x is greater or equal to y or Y is less than 3 then do the following code

or you can use and as well.
if a = true and b >= 14 then... if the value of a is true, or b is greater than or equal to 14 then do the following code.

uh im not sure I understand. Do you think you can input what I did? Like add to it? Since this example is hard to understand.

In safer lua syntax:
if (1 > 0) or (3 > 2) then [...]

well your statement has if 1>0 or 3>2 then do the code.
both statements are true, so it’ll do the code.
when you have something like
if you put if 5<0 that’s going to register as false so the code following that in the if statement won’t be done.
when you put
'if 5>0 or 3>2 then`
the first is false, but the second is true, so the or statement is checking both to see if either one is true and because one of them is true the code after it will be done.

what if it was like

if tonumber(TextBox.Text) >= 10 or <= 0 then

You’d want to verify that tonumber(TextBox.Text) returns a valid number type value before comparing it with other numbers values otherwise you’ll possibly encounter an “attempt to compare nil with number” error.

if tonumber(TextBox.Text) >= 10 or tonumber(TextBox.Text) <= 0 then

You also need to restate the values you’re comparing.

how do you verify it?

empty space

You’d need to provide that tonumber() twice for each comparison. Assert it’s also valid before doing it like:

local number = tonumber(TextBox.Text)
if number then
    if(number >= 10) or (number <= 0) then
        
    end
end

Well it still does not work :frowning:

Im not sure if this will help but heres the full script. Maybe that has something to do with it.

local TextBox = script.Parent
local Axis = TextBox.Name
local Error = script.Parent.Parent.Error
local Button = script.Parent.Parent.TextButton

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	TextBox.Text = TextBox.Text:gsub('%D+', '');
end)

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
	local Number = tonumber(TextBox.Text)
	if Number then
		if (Number >= 10) or (Number == 0) then
			TextBox.Text = tostring(TextBox.Text)
			Button.LocalScript.Disabled = true
			Button.MouseButton1Click:Connect(function()
				Error.Text = "Max part size limit is 10."
				Error:TweenPosition(UDim2.new(0,0,0.073,0),"Out", "Sine",.5)
			end)
		end
		if (Number <= 10) or (Number > 0) then
			TextBox.Text = tostring(TextBox.Text)
			Button.LocalScript.Disabled = false
			Button.MouseButton1Click:Connect(function()
				Error:TweenPosition(UDim2.new(-.2,0, 0.073, 0),"In", "Sine",.5)
			end)
		end
	end
end)
if false or true then
if true or true then
if false or false then

Or statements pick the first value that returns true.

Try a debug statement, like:

	local Number = tonumber(TextBox.Text)
	if Number then
       [...]
    else
        warn('TextBox.Text is non-numerical')
    end

It may not be doing anything because Number isn’t a valid number.
Additionally, your second if-statement should be an else-if since it’s a secondary comparison should the first if-statement evaluate false.

You might also want to be listening to .OnFocusLost from the TextBox instead of a “Text” changed signal, unless it’s necessary that your code is running on any change of input.

Someone correct me if I’m wrong, but won’t this make your Text = ‘’ if you inputed a number, therefore your other event won’t see the TextBox.Text as a number?