Attempted to index nil with 'Locked'

I am trying to edit this teleporter script to teleport the player that touches it to a part with the same name as their team. But I am having trouble with it. When I touch it I get an error reading “Attempted to index nil with ‘Locked’” on line 5. I tried searching solutions or what this means but I can’t seem to solve it or understand it.

function Touch (hit) 
	local Plr = hit.Parent.Name
	local Teleport = game.Players[Plr].Team
	local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		if script.Parent.Locked == false and script.Parent.Parent : FindFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:FindFirstChild(Teleport).Locked=true
			hit.parent:moveTo(Pos.Position) wait(1)script.Parent.Locked = false script.Parent.Parent:FindFirstChild(Teleport).Locked = false
		end
end
script.Parent.Touched:connect(Touch)

Thank you for any help in advance

Make sure the hit is actually a part before using Locked, if it is not a part then Locked is not a thing

1 Like

If you mean the parts the player interact with, they are both parts
image

Teleport has to be Team.Name your indexing a value with multiple properties

1 Like

hit.Parent might not be a part, it might be something else

Thank you I did not even notice I had made this mistake