Gsub but not with a string?

So I am making a plugin that gets the fullname of an ui object and makes a script. this is the script that it inserts but I need to get playergui not starter gui so i need to remove startergui from the name. but gsub doesn’t work. Any helps is great thanks!

local main = string.gsub("StarterGui.ScreenGui.Frame", "StarterGui.", "")
local players = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui") 


local full = players.main

Why wont you use :GetFullName() function

This is the script after my plugin inserted it. So I already got the full name and scense it was a UI object it was in starterGUI. so what I need to do is remove starterGUI from the name and replace it with playergui. But the Gsub doesn’t work because it can’t be a string.

This may do the trick if I understand your use case correctly.

local main = string.gsub("StarterGui.ScreenGui.Frame", "StarterGui.", "")
local players = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui") 

local function GetInstanceFromPath(start, path)
	local instance = start
	
	-- Use bracket notation to index children with a string
	for _, child in string.split(path, ".") do
		instance = instance[child]
	end
	
	return instance
end

local full = GetInstanceFromPath(players, main)
print(full)
1 Like

For this you can replace StarterGui with PlayerGui using gsub and then use my pathToInstance function:

So it should be:

local path = "StarterGui.ScreenGui.Frame"
local playerName = game.Players.LocalPlayer.Name
path = path:gsub("StarterGui.", "Players."..playerName..".PlayerGui.")

local full = pathToInstance(path)
print(full)
1 Like

the PathToInstance property has been removed from Roblox. It was previously used to get the path to an instance in the hierarchy, but it is no longer available. you can use the GetFullName() method to get the full path to an instance but i already have this and that is not the problem. I have said it above

That’s my own function, not something that’s built-in. Please carefully read a topic/reply before creating an answer.

I already stated above gsub doesn’t work so please read it carefully

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.