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
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
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
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.