"attempt to index nil with WaitForChild/Position" error

I’m attempting to make a monitor script, in which you can close/open doors and bring players in - however, the issue I have is bringing player’s in. I tried to debug and identify the issue, but I can’t seem to find a clue - there are around 5 monitors with the same script, it works twice, then afterwards it just breaks with this error. "attempt to index nil with WaitForChild/Position" for the lines:

local cPlr = whitelist[math.random(1, #whitelist)]
cPlr.Character:WaitForChild("HumanoidRootPart").Position = tpBlock.Position
local magnitude = (i.Character:WaitForChild("HumanoidRootPart").Position - game.Workspace.IntChecker.Position).Magnitude

What’s the issue with this script exactly?

	ui.Bring.MouseButton1Click:Connect(function()
		if not timeLimit then
			timeLimit = true
		local tpBlock = game.Workspace:FindFirstChild("IntTp"..val)
		local hasPlr = false
		local whitelist = {}
		for _, i in ipairs(game.Players:GetPlayers()) do
			local magnitude = (i.Character:WaitForChild("HumanoidRootPart").Position - game.Workspace.IntChecker.Position).Magnitude
			if magnitude <= 20 and i:GetRankInGroup(5301253) <= 6 then
				table.insert(whitelist, i)
				hasPlr = true
			else
				hasPlr = false
			end
		end
		if not hasPlr then
			ui.Bring.Text = "NO INTERVIEWEES"
			wait(.6)
			ui.Bring.Text = "BRING INTERVIEWEE"
		else
			local tpBlock = game.Workspace:FindFirstChild("IntTp"..val)
			local cPlr = whitelist[math.random(1, #whitelist)]
			print(cPlr)
			cPlr.Character:WaitForChild("Humanoid").Jump = true
			wait(.6)
			cPlr.Character:WaitForChild("HumanoidRootPart").Position = tpBlock.Position
			ui.Bring.Text = "BRUNG "..string.upper(cPlr.Name)
			wait(.6)
			ui.Bring.Text = "BRING INTERVIEWEE"
			end
		end
		wait(1)
		timeLimit = false
	end)
end)
1 Like

The issue seems to be that the Player’s Character does not exist, include an if statement to check that it isn’t nil.

1 Like

I added an if statement to check if it’s not nil, and apparently it’s not nil, but still shows me the error and doesn’t teleport them at cPlr.Character:WaitForChild("HumanoidRootPart").Position = tpBlock.Position.

1 Like

The issue was that I was missing parts in the workspace for it to function properly, thank you for the assistance though!

1 Like