So I've been trying for very long to make it so my teleporters don't teleport humanoid npcs. I couldn't think of a solution, find any youtube videos, wikis or any code that would seperate npcs from actual players for my teleporters. This is essentially a game breaking issue I need to fix since what happens is, it teleports my npcs and also causes a bunch of errors. The error I get seems to have something to do with the "Locked" word in the code.
If anyone knows the show Doctor Who, this might help you give me the right answer. I don't want daleks to step on a teleporter and get teleported to the tardis I only want real players able to do this.
Edit: Oh and I don't want them anchored.
The code below is for the teleporters
local Teleport = "te4"
function Touch(hit)
if not script.Parent.Locked and not
script.Parent.Parent:FindFirstChild(Teleport).Locked and
hit.Parent:IsA("Model") then
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
end
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
script.Parent.Touched:connect(Touch)

13 comments
Hmm your solution didnt seem to work and I don't know why. I'm pretty sure I put in the code correctly but nothing.
I completely forgot to mention this in my comment. When I added this, I wouldn't get teleported anymore and no errors appeared in the console.
Try adding some prints between lines of your code to know where it stops, like print("1") print("2") and so on, then tell me where it stopped.
Also why do you check if two things are locked? You don't need to check them twice for a cooldown, and you can actually create a value for that, like this: local teleportAvailable == true if teleportAvailable == true then teleportAvailable = false teleport code teleportAvailable = true end
Weird, I put a print at the beginning and the end. It managed to print both but in the middle of both prints I had a couple more prints that didn't work, and those prints were below "function Touch Hit" I put your code under that too btw. And to answer your question for why I check if two things are locked is because I'm a beginner scripter and I didn't realize that I could do what you just sent.
Look the edit I made on this post at the end.
Something isn't right.. its still not working. Hold on lemme see if the code I used before I used yours works. if it doesn't something is wrong.
Alright it works! But.. I get instantly teleported causing in a loop. I keep getting teleported back and forth. It seems like the cooldown code isn't working.
Here is the model with the parts I used with the code I posted: https://www.roblox.com/library/6376836177/. I created the parts based on what your code was saying, so it should work on yours, unless your parts aren't parented as they were intented to.
Ok, I managed to fix the loop but now the only problem is "te4" getting deleted from my game?? I have no code that does this but there are 3 teleporters that lead to this one teleporter, could it be because of this?
You can create a BoolValue and paster it inside the model, name it Cooldown, then change the code to check if that value is true instead of the cooldown value created inside the script. Then you can copy that script and paste it inside te4, and inside the cloned script change "te4" to the name of the other teleporter. About the "te4" deletion, It might be another script you have that's doing it.
Also it might be that "te4" isn't an anchored part, so check its properties and toggle te4 to anchored. If it isn't anchored nor set to collide, it will fall through your map and be deleted.
Your right! It isn't anchored?? I'm really confused because I'm not sure how this was unanchored. Huh well your solutions worked so thank you for helping me out!