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

How do you refer to an object with a space?

Asked by 10 years ago

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?

2 answers

Log in to vote
1
Answered by
d512634 10
10 years ago
local team = game.Teams["Red Rays"]

Am I right?

Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

Answer this question