Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you refer something if it has a space in it?

I have been trying to make a script that locally removes an object if they meet the requirements.

I've been having problems with referring to something in "Workspace"

Here's what I've already done:

game.Workspace.ObjectHere

This is what I need to do

game.Workspace.Object Here

As you know, that is invalid.

I understand that this is so weird that I do not know this. I probably should just give up on scripting right now. Anyway.. answers are appreciated! Thanks.

(please don't judge me)

2 answers

So given that tables are the quintessential data structuring type in Lua, it's unsurprising that userdata are in essence, tables.

Well, okay, why is this important? You see, the table.key syntax is not, in fact, that "standard" way to create/access entries. Rather, it's a sugarized version of table["key"].

This means that thing.Parent and thing["Parent"] are the same thing, with the latter being what the former is expanded to. So, when it comes time that we need to access a child of a given object, we have the option of doing Object["ChildName"] or Object.ChildName. Either is functionally indistinguishable from the other, it's purely personal preference -- That is, of course, until we need to access an entry/child with a space, at which point we must use the tabe["key"] syntax.

TL;DR:

game.Workspace.ObjectHere & game.Workspace["ObjectHere"] both access the object just fine, but only the game.Workspace["Object Here"] syntax supports objects with spaces in its name.

Well since everything inside the game and the explorer tab is essentially a table of properties and children, you can just index with the name of the thing, for example, if I have a part named "dubg odf" in workspace, i can do

local thing = workspace["dubg odf"]
print(thing.Parent,thing.Position)

also, I'm pretty sure :FindFirstChild() and WaitForChild() works as well

local thing = workspace:FindFirstChild("dubg odf")
print(thing.Parent,thing.Position)
-----------------------------------------------------
local thing = workspace:WaitForChild("dubg odf")
print(thing.Parent,thing.Position)

4 comments

0

I’ve been wondering this as well, but always just use Parent instead to go around the issue. This is good information!

0

thanks :3

0

You can also index it via name Example: game.Workspace["Some Object"].Name

0

ok cool but what do i do when the thing i want to recall is under two things with spaces in their names? do i just put it next to eachother or what

This discussion is preserved as it was. New answers, comments, and votes are closed.