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?
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?
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
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?