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

Is there a way to convert a string into the same location instance?

Asked by 3 years ago

Thanks for viewing my question.

So is there a way to convert string to instance such as converting “game.Workspace.testfolder” into game.Workspace.testfolder so you can do something such as:

location = converttoinstance(“game.Workspace.testfolder")— function you convert
test = instance.new(“Part”)
test.Parent = location

2 answers

Log in to vote
1
Answered by 3 years ago

Hmmm... I think this is the most efficient way of doing it...

local string = "testfolder" --assigns a string to a variable
local instance = game.Workspace:FindFirstChild(string) --finds the instance that has the same name as the string

or...

local instance = game.Workspace:FindFirstChild("testfolder")

But to know answer your question tho, I don't think there is another way of converting string to an instance. Hope this helps! :>

0
Thanks! It helps! SMORT idea! willywillycow 50 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

What you can do is like:

string1 = "Part"--Write the name of the Instance you want to create

local NewInstance = Instance.new(string1) --This will make a Part
NewInstance.Parent = workspace --You need to set the parent of the Instance too

I hope this helps

Answer this question