Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] Why does my IF statement acts like it is true, even though it is not?

Hey guys, I am making a GUI, and the if statement is doing like it's not there.. It is normal script - including explorer photo and code

--Variables
local Variables = game.Workspace.Variables
Hours = Variables.TV_1SessionTime.Hours
Minutes = Variables.TV_1SessionTime.Minutes

--Setup
local function SetTime()
				
	script.Parent.Time.Text = Hours.Value .. ":" .. Minutes.Value .. " ET"
		
	if script.Parent.Time.Text == '00:00 ET' or '0:00 ET' or '00:0 ET' then --<<IT IS FOR SOME REASON TRUE, EVEN WHEN IT IS NOT 00:00, 0:00 OR 00:0!
		
		script.Parent.Time.Text = "Error boi! No time."
		
	end
	
end

--Main code

script.Parent.Visible = true
SetTime()

Hours.Changed:connect(SetTime)
Minutes.Changed:connect(SetTime)

Explorer photo

Thanks in advance.

1 comment

0

Try "if script.Parent.Time.Text == '00:00 ET' or script.Parent.Time.Text == '0:00 ET' or script.Parent.Time.Text == '00:0 ET' then"

1 answer

✓ Accepted answer

I've had the same issues -- it's because Roblox is VERY picky.

You need to declare "if script.Parent.Time.Text == " behind every STRING.

Like this:

if script.Parent.Time.Text == '00:00 ET' or script.Parent.Time.Text == '0:00 ET' or script.Parent.Time.Text == '00:0 ET' then

I know the feels, I've encountered the same issue. I do not know exactly why the "if" statement can have certain variables as a "true" e.g. the strings presented in your "if" statement.

But yeah, if you don't want to type "script.Parent.Time.Text" 24/7, I'd define it before the if statement, like this:

local text = script.Parent.Time.Text
if text == '00:00 ET' or text == '0:00 ET' or text == '00:0 ET' then

Also, sometimes Roblox has trouble with defining properties of an instance, so I usually just like to define the instance instead of the property like this:

local text = script.Parent.Time
if text.Text == '00:00 ET' or text.Text == '0:00 ET' or text.Text == '00:0 ET' then

All 3 above should fix the problem.

5 comments

0

Thanks mate! How do I mark your answer as accepted btw?

0

I legitimately have no idea, I've made only 1 question and no one's ever responded to it lol. Although you could probably add [Solved] to the beginning of your question as to tell others that it was solved.

0

Just for context. the reason you have to do it the ways above is because the conditions between each or are individual statements, and a string on its own evaluates to True.

0

its not picky, its just standard logic

0

well I like to say its picky although it is code logic because its annoying lol

This discussion is preserved as it was. New answers, comments, and votes are closed.