Namify - Get the FullName of a Instance

Hello people of the dev forum :slight_smile:
Recently I started realising how much of a pain it was to get the path of an instance to use in a script and so I googled to see if there was a better solution to getting the full name of a part but there was nothing. So just the other day when I was bored I decided to just make it. I hope it’s something that can help you out when scripting and if you have any suggestions feel free to reply with them and I’ll look into it.

image

P.S. This is my first public plugin so please be nice and if you have any plugin suggestions feel free to reply and I might pick some that I think are nice.

8 Likes

Do you mean the function of Instance Instance:GetFullName() ? I think that does the same thing as your plugin, if I am understanding correctly.

1 Like

yeah, that’s exactly what the plugin uses. I just wanted to make a plugin that would make it easier instead of having to do :GetFullName() for every object.

The plugin helps you with getting an object path.

1 Like

just checked the plugin, simple & useful, but i still prefer game.Selection:Get()[1]:GetFullName()

I believe a better alternative to :GetFullName() would be this function:

local SpecialCharacters = {
	['\a'] = '\\a', 
	['\b'] = '\\b', 
	['\f'] = '\\f', 
	['\n'] = '\\n', 
	['\r'] = '\\r', 
	['\t'] = '\\t', 
	['\v'] = '\\v', 
	['\0'] = '\\0'
}
local Keywords = { 
	['and'] = true, 
	['break'] = true, 
	['do'] = true, 
	['else'] = true, 
	['elseif'] = true, 
	['end'] = true, 
	['false'] = true, 
	['for'] = true, 
	['function'] = true, 
	['if'] = true, 
	['in'] = true, 
	['local'] = true, 
	['nil'] = true, 
	['not'] = true, 
	['or'] = true, 
	['repeat'] = true, 
	['return'] = true, 
	['then'] = true, 
	['true'] = true, 
	['until'] = true, 
	['while'] = true, 
	['continue'] = true
}

local function GetFullName(Object)
	local Hierarchy = {}

	local ChainLength = 1
	local Parent = Object
	
	while Parent do
		Parent = Parent.Parent
		ChainLength = ChainLength + 1
	end

	Parent = Object
	local Num = 0
	while Parent do
		Num = Num + 1

		local ObjName = string.gsub(Parent.Name, '[%c%z]', SpecialCharacters)
		ObjName = Parent == game and 'game' or ObjName

		if Keywords[ObjName] or not string.match(ObjName, '^[_%a][_%w]*$') then
			ObjName = '["' .. ObjName .. '"]'
		elseif Num ~= ChainLength - 1 then
			ObjName = '.' .. ObjName
		end

		Hierarchy[ChainLength - Num] = ObjName
		Parent = Parent.Parent
	end

	return table.concat(Hierarchy)
end

because if you have a part name that uses reserved Lua keywords such as and, or a part with spaces (test part), then :GetFullName() wouldnt properly get those names - or at least it wouldn’t get the names with valid Lua syntax. This custom function I wrote would get the names properly, I.e workspace.andworkspace["and"] etc.

4 Likes

Really nice and cool idea. I’m thinking of using this in the plugin with some slight adjustments and improvements.

Don’t worry I’ll make sure to credit you.

UPDATE

Namify now supports syntax/operator characters (Thanks to @PysephDEV for the suggestion and an example of some code) as well as numbers. E.g. 1word, %percentage, ca$h.

If you have any issues or you feel I have missed a character feel free to reply to this message and I’ll check it out.