How can I get a object with its Full Name?

for example:

function GetObject(fullName)
--get a object with the parameter, fullName
end

local camFullName = workspace.Camera:GetFullName()
print(GetObject(camFullName)) --> workspace.Camera
--OF COURSE THERE AREN'T OBJECTS THAT HAVE SAME NAME.--

What should I code in function GetObject?

1 Like

What’s the purpose of this exactly? I think I know what you’re after, but there are very few reasons as to why you’d want to do that.

I presume you’re trying to get an instnace from a string, you can use something like this for the code in GetObject

function GetObject(fullName)
	local segments = fullName:split(".")
	local current = game

	for _,location in pairs(segments) do
		current = current[location]
	end

	return current
end

Took it from here and changed it up a bit

Basically it splits the full name from the dots, and then uses those splits as a way to navigate through the directory stating from game and ending up at the location needed

8 Likes

love you thats what i was looking for

1 Like