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

Teleport script can't find first child?

Asked by 8 years ago
Edited 8 years ago

I was looking for a teleport script in public models to learn more about it. I found a working one and tried to copy it over and it ended up not working. So I literally copy and pasted it to see if it would work that way. But unfortunately not. It is printing everything but "wow" and "We Did It Bois" In my output. I have two parts inside of a model named "Teles" these parts are named "teleport1" and "teleport2". This is Teleport 1's script. It always returns with

Koala lel cool
nil
No Telelocation

I have literally looked over this hundreds of times looking for whats wrong but I can't get a hold of it. It looks as if it can't find the child of Tele named as "teleport2". As it is returning with "nil".


function onTouched(part) if part.Parent ~= nil then print("Koala") local h = part.Parent:findFirstChild("Humanoid") if h~=nil then print("lel") local teleportfrom=script.Parent.Enabled.Value if teleportfrom~=0 then print("cool") if h==humanoid then print("wow") return end local teleportto=script.Parent.Parent:FindFirstChild("teleport2") print(teleportto) if teleportto~=nil then print("We Did It Bois") local torso = h.Parent.Torso local location = {teleportto.Position} local i = 1 local x = location[i].x local y = location[i].y local z = location[i].z x = x + math.random(-1, 1) z = z + math.random(-1, 1) y = y + math.random(2, 3) local cf = torso.CFrame local lx = 0 local ly = y local lz = 0 script.Parent.Enabled.Value=0 teleportto.Enabled.Value=0 torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz)) wait(3) script.Parent.Enabled.Value=1 teleportto.Enabled.Value=1 else print("No telelocation") end end end end end script.Parent.Touched:connect(onTouched)
0
What is your script trying to do? Monsieur_Robert 338 — 8y
0
Teleport a player from "teleport1" to "teleport2". TheGreatGoryGamer 20 — 8y

1 answer

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

In order to teleport a player, all you need to do is use the CFrame property on the player's HumanoidRootPart. For example, you might want to do something like this in your teleport1 brick (of course, you will need to tailor it to your needs). Simple:

I have not tested this script-in game, so if you get any errors using the script please let me know.

script.Parent.Touched:connect(function(part)
    if not part.Parent and not part.Parent:FindFirstChild("Humanoid") then return end -- This makes sure that an actual character is touching the brick. First all of all, we make sure that the part that touched has a parent, and then we make sure that there is a humanoid in the part's parent (this is a good way to make sure we are dealing with a player). If neither of those conditions are met, then we "return".
    local character = part.Parent -- This is the character model that we want to move.
    character.CFrame = CFrame.new(Vector3.new(0, 0, 0)) -- The vector3 is the position on the 3D axis that you want your player to move to. In your case you will probably want to set the position to the position of your teleport2.
end)
Ad

Answer this question