Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

Output?

0

What does it output

2 answers

✓ Accepted answer

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.

3 comments

0

Supposed to work, I tested in studio.

0

It works! Thank you so much for your answer, this will really help me with my new game.

0

Np! :D

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

7 comments

0

That can't be the problem as it works before he hit with a tool

0

Yea, it works before I use a tool on it. That sadly didn't fix my problem. Thanks for answering though.

0

what is the error in the output

0

@keiujir When I touch it with a tool, it says "moveTo is not a valid member of Tool" in the output

0

That's because it's not a player, check my answer.

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

0

youre supposed to put that in answers tho

This discussion is preserved as it was. New answers, comments, and votes are closed.