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

When do you store a property as a variable? [closed]

Asked by 6 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

I see lots of code like this:

local text = script.Parent.Text

text = 'hi how ru'

What they are doing is assigning the text variable the current Text of the label/button/box.

They write that code thinking the text will change. But they are wrong. They are just reassigning the text variable.

To fix this:

local text = script.Parent

text.Text = 'hi how ru' 

The above code will change the text because of the .Text added.

Just to clear things up. Don’t assign a variable a property that is not an object. For example: local part = script.Parent

That line would be okay since it is referring to an object, the Parent.

0
^ Amiaa16 3227 — 6y
0
I had to figure this out myself through trial and error when I started coding. Was frustrating lol TiredMelon 405 — 6y
0
lol same^ don’t want new scripters following in our footsteps User#19524 175 — 6y
0
Another up-vote ^ TheSkyofIndia 150 — 6y

Closed as Not Constructive by Avigant and User#5423

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?