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

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

Asked by 5 years ago

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

Log in to vote
1
Answered by
systack 123
5 years ago

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.

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
I’ve been wondering this as well, but always just use Parent instead to go around the issue. This is good information! DinozCreates 1070 — 5y
0
thanks :3 theking48989987 2147 — 5y
0
You can also index it via name Example: game.Workspace["Some Object"].Name M39a9am3R 3210 — 5y
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 hermandise345 0 — 3y

Answer this question