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

Is it possible to use a variable as a location?

Asked by
Bman8765 270 Moderation Voter
9 years ago

Basically I want to know if you can use a variable for the name of locating a file. I'll give you an example below (it might not be right though which is why I'm asking how to do it) I was just curious if this is how you do it or there is another way. (In this case part1 is a part in workspace with the name part1 I'm just using a variable string value) Don't ask why I need this, I'm just curious and wanna know.

thebestpart = "part1"

game.Workspace.thebestpart.Transparency = 0

1 answer

Log in to vote
3
Answered by
Discern 1007 Moderation Voter
9 years ago

You can, but you must use brackets in the form of [string].

Here would be a working script:

thebestpart = "part1"

game.Workspace[thebestpart].Transparency = 0 --Note the period after the brackets and not before.
0
Thanks Bman8765 270 — 9y
0
Np. :) Discern 1007 — 9y
Ad

Answer this question