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

Teleporter script Help?

Asked by
iLegitus 130
9 years ago
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

2 answers

Log in to vote
0
Answered by 9 years ago

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.

Ad
Log in to vote
-1
Answered by 9 years ago

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.
0
Wow how'd I get 2 thumbs down? I'm just telling him some tips. Plus both scripts work. The other guy's is more convenient I must say, but why the salt? The only place that needs salt is the roads in front of my house.  EzraNehemiah_TF2 3552 — 9y
0
You were downvoted because your answer has incorrect information. The Position property is a Vector3 and using the not operator is not needed and just preference. NotsoPenguin 705 — 9y
0
Even though "not" is just s preference, I still had the right answer. I did see some mistakes and I fixed them. EzraNehemiah_TF2 3552 — 9y

Answer this question