I have a teleporter script here:
1 | local Teleport = "PartB" |
2 | function Touch(hit) --Indicates that the Part has been Touched. |
3 | 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. |
4 | local Pos = script.Parent.Parent:findFirstChild(Teleport) --Gets the Part to teleport to. |
5 | 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. |
6 | 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.
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)
1 | local Teleport = "PartB" |
2 | function Touch(hit) |
3 | if hit.Parent:FindFirstChild( "Humanoid" ) then -- Detect the Humanoid |
4 | 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 |
5 | local Pos = script.Parent.Parent:findFirstChild(Teleport) |
6 | hit.Parent:moveTo(Pos.Position) wait( 1 ) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end |
7 | end |
8 | 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.
What i think is wrong is that you misspelled FindFirstChild it should FindFirstChild and not findFirstChild