Attempt to index nil with 'MoveTo'

Hi, I am trying to get the players name from a folder then teleport them to a part

Script

local TP = game.Workspace.TP
script.Parent.Value.Changed:Connect(function(val)
	script.Parent.Parent.Part.BillboardGui.TextLabel.Text = "Queue: "..val.."/2"
	if script.Parent.Value.Value == 2 then
		for v, name in pairs(script.Parent.Queue:GetChildren()) do
			print(name)
			game.Workspace:FindFirstChild(name).PrimaryPart:MoveTo(TP.Position)
			TP.Value.Value = true
			local PpP = Instance.new("StringValue")
			PpP.Name = name
			PpP.Parent = TP.Players
		end
		wait(2)
		print("ajsd")	
	end
end)

try changing it to this if you want to make the player walk to the part:

local TP = game.Workspace.TP
script.Parent.Value.Changed:Connect(function(val)
	script.Parent.Parent.Part.BillboardGui.TextLabel.Text = "Queue: "..val.."/2"
	if script.Parent.Value.Value == 2 then
		for v, name in pairs(script.Parent.Queue:GetChildren()) do
			print(name)
			game.Workspace:FindFirstChild(name).Humanoid:MoveTo(TP.Position) -- use humanoid here
			TP.Value.Value = true
			local PpP = Instance.new("StringValue")
			PpP.Name = name
			PpP.Parent = TP.Players
		end
		wait(2)
		print("ajsd")	
	end
end)

I think it only works if you use the Humanoid instead of the PrimaryPart.

If you want to teleport the player without making him walk use this:

local TP = game.Workspace.TP
script.Parent.Value.Changed:Connect(function(val)
	script.Parent.Parent.Part.BillboardGui.TextLabel.Text = "Queue: "..val.."/2"
	if script.Parent.Value.Value == 2 then
		for v, name in pairs(script.Parent.Queue:GetChildren()) do
			print(name)
game.Workspace:FindFirstChild(name):SetPrimaryPartCFrame(TP.CFrame)
TP.Value.Value = true
			local PpP = Instance.new("StringValue")
			PpP.Name = name
			PpP.Parent = TP.Players
		end
		wait(2)
		print("ajsd")	
	end
end)

Workspace.Part.ClickDetector.Script:52: attempt to index nil with ‘SetPrimaryPartCFrame’

Having and error with both

but in the print statement it prints the players name so Idk why its not working

Only Models can use MoveTo, just remove the .PrimaryPart before :MoveTo and it should work. But also consider :PivotTo, as it works more reliably.

image
Still having the same problem

Could you show your new code that caused this error?

1 Like
for v, name in pairs(script.Parent.Queue:GetChildren()) do
			print(name)
			game.Workspace:FindFirstChild(name):PivotTo(TP.CFrame)
			TP.Value.Value = true
			local PpP = Instance.new("StringValue")
			PpP.Name = name
			PpP.Parent = TP.Players
end

What is in the Queue object? Are they player names?

1 Like

Ok after reading your script I realized the issue, the Queue was a folder and the names that were in there was a sting value with the players name so I was trying to find the string value in workspace so all I had to change was

game.Workspace:FindFirstChild(name.Name):PivotTo(TP.CFrame)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.