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

Teleporter not working after being touched with a tool. Why?

Asked by 4 years ago

I have a teleporter script here:

local Teleport = "PartB"
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 = script.Parent.Parent:findFirstChild(Teleport) --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.

It works perfectly. But when I hold out a tool and touch the teleporter part, it stops working. I cannot use it anymore. I don't know if others can, I haven't done a multiplayer test yet. Can someone please help? Also, sometimes I come into game and it just doesn't work, even if I did nothing to it. I have to rejoin. I think that's only in Studio though, idk.

0
Output? LUCATIVIOMAD2 54 — 4y
0
What does it output LUCATIVIOMAD2 54 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The reason is that the tool don't have a humanoid. To fix, use this script: (Just added a thing to make it detect humanoid)

local Teleport = "PartB"
function Touch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then  -- Detect the Humanoid
        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 
        local Pos = script.Parent.Parent:findFirstChild(Teleport) 
            hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end 
        end
script.Parent.Touched:connect(Touch)

As to your "doesn't work when joined", I think the reason is that the script's function detected the hit as the Accessory instead of the player. It should be fixed with this script.

0
Supposed to work, I tested in studio. LUCATIVIOMAD2 54 — 4y
0
It works! Thank you so much for your answer, this will really help me with my new game. OrbitOps 34 — 4y
0
Np! :D LUCATIVIOMAD2 54 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

What i think is wrong is that you misspelled FindFirstChild it should FindFirstChild and not findFirstChild

0
That can't be the problem as it works before he hit with a tool LUCATIVIOMAD2 54 — 4y
0
Yea, it works before I use a tool on it. That sadly didn't fix my problem. Thanks for answering though. OrbitOps 34 — 4y
0
what is the error in the output Baselistic 103 — 4y
0
@keiujir When I touch it with a tool, it says "moveTo is not a valid member of Tool" in the output OrbitOps 34 — 4y
View all comments (3 more)
0
That's because it's not a player, check my answer. LUCATIVIOMAD2 54 — 4y
0
@ovyxn dude, MoveTo() is for players, you either use script.Parent.Parent.CFrame or script.Parent.Parent.Position if you want to teleport a part guest_20I8 266 — 4y
0
youre supposed to put that in answers tho LUCATIVIOMAD2 54 — 4y

Answer this question