I am writing a script that will detect when a button is clicked, then will disable the parent screengui and teleport the player to the position of a part in the workspace.
I was facing 2 errors previously,
TeleportPart is not a valid member of Workspace “Workspace"
and
infinite yield possible on WaitForChild:(“TeleportPart”) --When I used this
After an hour of troubleshooting, I have not found the issue with my code.
Here is my localscript:
local button = script.Parent
local mainMenu = button.Parent
button.Interactable = true
task.wait(.001)
local player = game.Players.LocalPlayer
local teleportPart
repeat
teleportPart = game.Workspace:FindFirstChild("TeleportPart")
task.wait()
until teleportPart
button.MouseButton1Click:Connect(function()
print("Button Clicked")
button.Interactable = false
local character = player.Character
local humanoidRootPart = character.WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = teleportPart.CFrame
mainMenu.Enabled = false
end)
here is my explorer:
I would appreciate some support with this and I can answer any extra questions you may have



