Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

bad argument #1 to '?' (Vector3 expected, got nil),fix please.

target = game.workspace:WaitForChild('Teleport'):GetChildren()
for i, player in pairs(game.Players:GetChildren()) do
   if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
	 local torso = player.Character:WaitForChild('Torso')
         torso.CFrame = CFrame.new(target.Position + Vector3.new(0,2,0))
	

   end
end

The bug is in line 05.

1 comment

0

More information.

1 answer

✓ Accepted answer

Your variable "target" was only returning nil. This should work.

for a,b in pairs(game.Workspace:WaitForChild('Teleport'):GetChildren()) do
	for i, player in pairs(game.Players:GetChildren()) do
		if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
			local torso = player.Character:WaitForChild("Torso")
			torso.CFrame = CFrame.new(b.Position + Vector3.new(0,2,0))
		end
	end
end

Here are two links for more information on why this didn't work and how you can debug in the future:

ROBLOX Wiki - API:Class/Instance/GetChildren

YOUTUBE - 'Print Debugging' by ROBLOX

If this helped you please accept the answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.