Lets say I have a team called Red Rays. How can I refer to it without changing the name? For example:
local team = game.Teams.Red Rays --This doesn't work local Team = game.Teams:FindFirstChild("Red Rays") --This returns a boolean local Team1 = game.Teams.Red_Rays --I don't want to change the name
Anything I can do?
The period (.key
) for access on an object is sugar for normal table access using a string as a key (i.e., accessing using [key]
).
a.b
is considered by the interpreter to be doing a["b"]
.
So if an object has a space in its name, you can refer to it using that version, instead:
Object["Spaced Named"]
To underscore the concept, remember that you can use this always:
game["Workspace"]["Part"]["Transparency"] = 0.5
Alternative, you could use FindFirstChild
since it always takes a string as a parameter to begin with (but is much more verbose).
Also, FindFirstChild
does not return a boolean, it returns an object. All objects are truthy, though, which is why it is used in if
statements.