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

How to use a variable in reference path?

Asked by 5 years ago
Edited 5 years ago

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.

0
Is it part28, or mistake here? GooierApollo664 183 — 5y
0
Oh, it's meant to be a string, my bad. Doge_Brigade 94 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
partName = "part28"
local part = game.Workspace.MyFolder.Model[partName]
0
Thanks! Doge_Brigade 94 — 5y
0
You are welcome! Igoralexeymarengobr 365 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

If Parts name changes you can do

partName = part.Name
local part = game.Workspace.MyFolder.Model:FindFirstChild(partName)
0
Also a wait! Doge_Brigade 94 — 5y
0
way* Doge_Brigade 94 — 5y

Answer this question