Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why did it cause an error that I do not feel relates to the problem?

Asked by
qVision 12
7 years ago
Edited 7 years ago
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?

0
FindFirstChild returns the first child found with that name or nil, if torso is not found then it will be nil. User#5423 17 — 7y
1
But it should find the Torso whenever I step on my part right? qVision 12 — 7y
2
Only if a part named Torso is found ie r6 not r15. User#5423 17 — 7y
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. GoldenPhysics 474 — 7y

Answer this question