A simple scripting question

IDK what is the right here

game.workspace["Part name with space"]:Destroy()

or

game.workspace.["Part name with space"]:Destroy()

Assuming your question is a “which one works”, the first one will work and the second one will not.

1 Like

There are two ways to get a child element in roblox, using a dot/period syntax (ie. parent.child) or bracket syntax (ie. parent["child"]).

We typically use dot syntax, however if the child has a name with whitespace or that starts with a letter not in an alphabet, it won’t work, such as 1st Text Label. To bypass this problem, we can either change the name of the child, such as changing it to TextLabel1 or FirstTextLabel, or if it is ideal to not change the name, we can use bracket syntax, as it uses a string, so we can identify a child with any name, this includes names with whitespace.

1 Like