#Is it possible to call a child using a string variable?

15 messages · Page 1 of 1 (latest)

nimble crater
#

Ex:

local var = "X"
var = "Y"

script.Parent.(var).Visible = true

Super simple question but I can't find anything about it online. I'm new to scripting

visual lion
#

script.Parent[var].Visible = true

#

Or script.Parent["Y"].Visible = true

nimble crater
#

Appreciate it, thanks.

visual lion
#

Same applies to tables

#
local tbl = {["Silly Do Dad"] = 5}

print(tbl["Silly Do Dad"] -- -> Output: 5
violet sandal
#

Could also use script.parent:FindFirstChild(var) but generally just do as snicka says

toxic hinge
#

@nimble crater using indexing like that also searches through the objects properties

#

So in the rare case that you're looking for a child with a property name it'll get weird

visual lion
violet sandal
violet sandal
visual lion
#

It’s micro optimization but yeah

#

You’ll save like a tenth of a second so the performance loss is very low