How do I find a TextLabel with a specific text?

Been using this code but it’s not working.

local OfficeTeleportScript = game.StarterGui[“Put in StarterGui”].Button.LocalScript

local function FindOfficeButton()
for i,OfficeButton in ipairs(game.Players:GetDescendants()) do
if OfficeButton:IsA(“TextLabel”) then
if OfficeButton.Text == “Whats good” then
print (“Button Found”)
end
end
end

while true do
local target = FindOfficeButton()
if target then
OfficeTeleportScript.Parent=target.Parent
end
end

task.wait(0.01)

end

Alright, this code is a big mess.

What is your end goal for the code, we could probably make this much… much more efficient.

Basically I want to put a script inside of a GUI text box with a specific text.

What is that scripts purpose?

odjfgnfgodf - more letters

Yeah, you’ll probably want to go about this a different way. But, I’ll show you what went wrong in your code. Firstly, you put one too many ends on the FindOfficeButton function and added one too many ends on the “while true do” loop. Next, you should be moving the OfficeTeleportScript from the players PlayerGui, not StarterGui. Lastly, in this line

local target = FindOfficeButton()

target will always be nil since you never returned the button that the function found.

local player = game.Player.LocalPlayer
local PlayerGui = player.PlayerGui
local OfficeTeleportScript = PlayerGui["Put in StarterGui"].Button.LocalScript

local function FindOfficeButton()
	for i,OfficeButton in ipairs(PlayerGui:GetDescendants()) do
		if OfficeButton:IsA("TextLabel") then
			if OfficeButton.Text == "Whats good" then
				print ("Button Found")
				return OfficeButton
			end
		end
	end
end

while true do
	task.wait()
	local target = FindOfficeButton()
	if target then
		OfficeTeleportScript.Parent = target.Parent
	end
end

The script teleports you when you click a gui button that it is inside of. I want you to teleport when you click on a certain dialogue option. I’m using a dialogue plugin so the whole dialogue gui doesnt pop up isnt in the game until you click on a speech bubble

Massive thanks! But it didn’t work, It never printed “Button Found” nor put the script inside of the target’s parent.

That’s good to hear, though this method is really bad practise, and you should just put the script inside of the GUI already. Rather than adding it after, which makes no sense.

I am using a dialogue plugin, so the GUI is not in the game, until you interact with the speech bubble, then a GUI is created in the game and so thats why I am trying to make a script that inserts the teleport script into a dialogue option in the GUI with the specific words

Could you send a link to the plugin you’re using.

If you’re not able to add code using that, I’d recommend just writing your own system.
This is horrible code practice because it depends on multiple things.

here is the thread for the original version which is old and broken.

https://www.roblox.com/library/2921269188/Glossys-Dialog-Editor-Fork
I am using this “fixed” version and there is supposed to be a function that allows you to put scripts into your dialogue options but that doesn’t work.

Yeah, that plugin is pretty out-of-date. I’d recommend finding another one, or coding your own system.