Finding and changing a property based on String?

When using a string surrounded by brackets next to an Instance, you’re only searching for children of the Instance. The same goes for :FindFirstChild (as made clear by the name). Is there a way to change a property of an Instance by finding it with a string?

Example:

local PropertyToFind = “Name”

InstanceValue[PropertyToFind] = “This should change the value of the Instance’s name.”

Unless I misunderstood what you’re asking, theoretically you can change the properties like this.

local Property = "Name"
local Value = "test"

Part[Property] = Value
1 Like

if InstanceValue[PropertyToFind] and not InstanceValue:FindFirstChild(PropertyToFind) then should be the statement, I guess?

4 Likes

Whenever you reference something in an instance, first the properties are searched for that name. If it does not find any property of that name, then it searches the children.

If you put a folder named “Text” inside a TextLabel object, and you try to reference the folder, it will reference the .Text property of the TextLabel object instead.

I don’t know why I didn’t think about this before the thread, thanks for all these responses.

1 Like