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)
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)