Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited 5 years ago

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.

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" LawlR 182 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Thanks mate! How do I mark your answer as accepted btw? Doge_Brigade 94 — 5y
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. Cvieyra2test 176 — 5y
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. farizarps 132 — 5y
0
its not picky, its just standard logic Gey4Jesus69 2705 — 5y
0
well I like to say its picky although it is code logic because its annoying lol Cvieyra2test 176 — 5y
Ad

Answer this question