local Teleport = "SFArenaTPTO" --Put the name of the Part between the "" function Touch(hit) --Indicates that the Part has been Touched. 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 --Checks Debounce. local Pos = game.Workspace.SFArenaTPTO --Gets the Part to teleport to. hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end --Takes you there and Ends the Function. script.Parent.Touched:connect(Touch) --Listens out for Touchers.
Output says :
14:02:59.779 - Workspace.Lobby.SFingTeleporter.Script:3: attempt to index a nil value 14:02:59.779 - Stack Begin 14:02:59.781 - Script 'Workspace.Lobby.SFingTeleporter.Script', Line 3 14:02:59.783 - Stack End
The error is saying that FindFirstChild
did not find the part. There is no point in using FindFirstChild
if you are just going to use it right away.
Also MoveTo
must have a capital m.
local Teleport = "SFArenaTPTO" --Put the name of the Part between the "" function Touch(hit) --Indicates that the Part has been Touched local p = script.Parent.Parent:findFirstChild(Teleport) if p and script.Parent.Locked == false and p.Locked == false then script.Parent.Locked = true p.Locked = true local Pos = game.Workspace.SFArenaTPTO --Gets the Part to teleport to. hit.Parent:MoveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false else print("Part not found") end end script.Parent.Touched:connect(Touch) --Listens out for Touchers.
Instead of if foo == false then
try if not foo then
. if not
checks to see if it DOESN'T exist or is false. It's just more convenient.
Your mistake was that when you said :MoveTo()
. Inside of those parentheses, there should be a Vector3 value. So just add a Vector3.new()
too it. I edited your script to be more convenient.
local Teleport = game.Workspace.SFArenaTPTO --Put the object here. function Touch(hit) --Indicates that the Part has been Touched. if not script.Parent.Locked and not Teleport.Locked then script.Parent.Locked = true Teleport.Locked = true --Checks Debounce. local Pos = Teleport.Position --Gets the position of the part. hit.Parent:MoveTo(Vector3.new(Pos.X,Pos.Y+1,Pos.Z)) --Capital M in :MoveTo() wait(1) script.Parent.Locked = false Teleport.Locked = false end end --Takes you there and Ends the Function. script.Parent.Touched:connect(Touch) --Listens out for Touchers.