local telestart = script.Parent
local teleend = game.Workspace.TeleEnd

function teleportPlayer(part)
	local torso = part.Parent:FindFirstChild("Torso")
		torso.CFrame = CFrame.new(teleend.Position) + Vector3.new(0,10,0)
		print(1)	--For testing
	end
	


telestart.Touched:connect(teleportPlayer)

18:30:28.647 - Workspace.TeleStart.Script:6: attempt to index local 'torso' (a nil value)

I'm using my body parts to help make the parameter function( eg. Left Leg). Although I have found the solution to this script, and that is that I made the torso in line 6 position itself into my body parts. I want to know why it caused the error above?

4 comments

0

FindFirstChild returns the first child found with that name or nil, if torso is not found then it will be nil.

1

But it should find the Torso whenever I step on my part right?

2

Only if a part named Torso is found ie r6 not r15.

0

You need to check that it actually found the Torso. With your code, even if it doesn't find the torso, it'll try to set the CFrame.