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

Why is my very primal/simple GUI script erroring?

Asked by 7 years ago
script.Parent.SearchBar:connect(onChanged()
if script.Parent.SearchBar.Text ~= "" or " " then
    script.Parent.SearchBarBG.Visible = false
end)
    end


script.Parent.SearchBar:connect(onChanged()
if script.Parent.SearchBar.Text == "" or " " then
    script.Parent.SearchBarBG.Visible = true
end)    
    end

1 answer

Log in to vote
1
Answered by 7 years ago

Before I begin, please, when you have the time, review this article.

Now, to begin:

Line 3 is your problem: they're not saying if the value is not equal to [blank] then execute, else if [blank-space] is true then execute.

For every time you want to check a value, you can't do it the way you have done it here: even though it means repeating the same thing over-and-over, it's a must.

I also suggest you use a Variable for the SearchBar object, as what you've done is not good practice, and gets repetitive. Fast.

Whats more, you didn't create/ define a Function named onChanged prior to the connection part of the script; you just pulled it out of nowhere(!?!)

Last but not least, you rewrote the same code TWICE; you only need one in this case!

This is how your code should look; however, I'm NOT rewriting & redoing the whole script for you: that's your job.

local SearchBarObject = script.Parent:WaitForChild('SearchBar') -- The WaitForChild function yields the code until a child w/ the same name as the argument given exists w/in the specified parent; this is how to prevent the whole thing getting repetitive when rewriting the same thing over-and-over w/ a lot to type.

local StringComparisonExample = 'I\'m a string :P' -- String example; will be used in the following code to demonstrate string comparisons

if StringComparisonExample ~= 'I\'m a wizard! :D' or StringComparisonExample ~= 'I\'m Merasmus!' then -- This is how it should be done, w/ the case of your code; will check to see if the comparison/ value(s) return true, if not, it goes to the "else" statement; if value is not equal to value then return true, if value is not equal to second value then return true
    print('I\'m not a wizard ;c')
else
    print('MERASMUS!')
end

Again, I'm not rewriting your entire code: that's your job; the examples I gave are for reference ONLY.

Please take these notes/ pointers into consideration; it'll help you in the future. :)

Btw, I didn't mean to sound mean, rude or harsh: it's just how you did your code and set it up, as well as your question; please read the article that which I pointed out in the beginning for future reference. :)

0
Seems to be broken or im missing the meaning because I can only get it to print: "I'm not a wizard ;c" AlexColton 29 — 7y
0
Yeah, b/c the StringComparisonExample variable doesn't match up w/ either of the strings presented on line 5 (of the above example). :P TheeDeathCaster 2368 — 7y
Ad

Answer this question