Attempt to index nil with 'CFrame'

I’m trying to make a teleporter where if a specific object with a name touches it, it teleports to the other teleporter. I have tried making and else if block.CFrame == nil then and so but still haven’t achieved it. Here is the script that I made and the explorer menu also:

local plrs = game:GetService("Players")
local tp1 = game:GetService("Workspace").TelePads1
local tp2 = game:GetService("Workspace").TelePads2

plrs.PlayerAdded:Connect(function(plr)
	local block = game:GetService("Workspace"):FindFirstChild(plr.Name .. "'s Block")
	
	for _, part in ipairs(tp1:GetChildren()) do
		for _, part2 in ipairs(tp2:GetChildren()) do
			local pos = part2.CFrame
			part.Touched:Connect(function(touch)
				if part.Num.Value == part2.Num.Value and touch.Parent == game:GetService("Workspace") then
					print(pos)
					block.CFrame = pos
				end
			end)
		end
	end
end)

slika_2025-01-25_134102730
“Ignore the HumTelePads, just the Telepads”

A few issues here, you are calling the loop every time a player joins so it will just stack up until forever. You are also calling a second loop inside another loop which doesnt make sense, I decided to remake your script:

local tpparts = workspace.TpParts
local tp1 = tpparts.Tp1
local tp2 = tpparts.Tp2

tp1.Touched:Connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		char:PivotTo(tp2.CFrame)
	end
end)

If you want multiple teleporters in teleport 1 to teleport to teleport2s accordingly you can use something like this:


local tp1Parts = workspace.Tp1:GetChildren()
local tp2Parts = workspace.Tp2:GetChildren()

for i, tp in ipairs(tp1Parts) do
	tp.Touched:Connect(function(hit)
		if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			local char = hit.Parent
			char:PivotTo(tp2Parts[i].CFrame)
		end
	end)
end