Attempt to index nil with 'CFrame'

I need to make a gui button,that will teleport you to the bossfight.But apparently,the line 6 gives an error: “attempt to index nil with ‘CFrame’”.I’ve never really encountered that before.
Anyways,here’s the script:

local part = workspace:FindFirstChild("TeleportPart")
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
	if humanoidrootpart then
		humanoidrootpart.CFrame = part.CFrame
	end
end)

on local, some parts take a while to load, change FindFirstChild to WaitForChild:

local part = workspace:WaitForChild("TeleportPart")
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local humanoidrootpart = plr.Character:WaitForChild("HumanoidRootPart")
	if humanoidrootpart then
		humanoidrootpart.CFrame = part.CFrame
	end
end)

it now says:“Infinite yield possible on ‘Workspace:WaitForChild(“TeleportPart”)’”.

try

if humanoidrootpart and part then
		humanoidrootpart.CFrame = part.CFrame
	end

Your part does not exist then, send screenshot of your workspace?

Снимок экрана 2024-09-17 202820

local part = workspace:WaitForChild("TeleportPart")
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local humanoidrootpart = plr.Character:WaitForChild("HumanoidRootPart")
	if humanoidrootpart then
		if part then
			humanoidrootpart.CFrame = part.CFrame
		else
			print("TeleportPart does not exist")
		end
	else
		print("HumanoidRootPart Does not exist")
	end
end)

try this script.

It says,that the teleport part doesn’t exist if i put “FindFirstChild”,else, it just says,that “Infinite yield possible on ‘Workspace:WaitForChild(“TeleportPart”)’”.

Okay so lets try adding timeout:

local part = workspace:WaitForChild("TeleportPart",5)
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local humanoidrootpart = plr.Character:WaitForChild("HumanoidRootPart")
	if humanoidrootpart then
		if part then
			humanoidrootpart.CFrame = part.CFrame
		else
			print("TeleportPart does not exist")
		end
	else
		print("HumanoidRootPart Does not exist")
	end
end)

It yet still has the same error.

When does TeleportPart come into existence? It clearly doesn’t exist at the start of the game

Are you sure that TeleportPart Exists in the workspace?

He did send screenshot, and it does exist but i dont know where

it does exist in workspace.(idk what to add)

I added a wait before the script/

task.wait(1.5)
local part = workspace:WaitForChild("TeleportPart")
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	local humanoidrootpart = plr.Character:WaitForChild("HumanoidRootPart")
	if humanoidrootpart then
		if part then
			humanoidrootpart.CFrame = part.CFrame
		else
			print("TeleportPart does not exist")
		end
	else
		print("HumanoidRootPart Does not exist")
	end
end)

“Infinite yield possible on ‘Workspace:WaitForChild(“TeleportPart”)’”.

Select the Part, and check if Archivable property enabled in the property’s menu.

yes,it is enabled in the property’s menu.

make sure that its name is TeleportPart luau is case sensitive
you are getting that error because FFS and WFC will return nil if instance wasnot found and nil doesnot have CFrame

yes,it has the same name as in the script.