Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use a variable in reference path?

Hey guys, I have a part name stored in a variable, it changes regularly, being in a for loop. As I said, it's a part and I need to use the path to it, but as it changes, I can't enter/concencate/insert the variable/part name in there.

This is what I'm aiming for:

partName = "part28"
local part = game.Workspace.MyFolder.Model.--and here put the value of 'partName'

How would I achieve this?

Thanks in advance.

2 comments

0

Is it part28, or mistake here?

0

Oh, it's meant to be a string, my bad.

2 answers

✓ Accepted answer
partName = "part28"
local part = game.Workspace.MyFolder.Model[partName]

2 comments

0

Thanks!

0

You are welcome!

If Parts name changes you can do

partName = part.Name
local part = game.Workspace.MyFolder.Model:FindFirstChild(partName)

2 comments

0

Also a wait!

0

way*

This discussion is preserved as it was. New answers, comments, and votes are closed.