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

How to script Teleporting?

Asked by 10 years ago

I have a spawn room and I want to teleport them to the arena. I haven't tried any code because I know it's going to fail. Do I have to take the coordinates of both areas to make it work? I don't want to use bricks, just a script that does it automatically.

2 answers

Log in to vote
1
Answered by 10 years ago

Ok, first create and set a localscript in the StarterGui You need to declares some variables, let's do it!

local player = game.Players.LocalPlayer -- Returns the player that is running the script

-- Instead of X, Y and Z use your own coordinates, use blocks for faster navigation, get their position and paste there, after that remove the block ;)
local startingPos = Vector3.new(x, y, z) -- Where will the starting position be located?
local endingPos = Vector3.new(x, y, z)  -- And the ending?

Ok now we need to make the teleport function! But first, let me take a... emh sorry...we need to make a boolean variable that check if the player is already in the arena!

local player = game.Players.LocalPlayer -- Returns the player that is running the script

-- Instead of X, Y and Z use your own coordinates, use blocks for faster navigation, get their position and paste there, after that remove the block ;)
local startingPos = Vector3.new(x, y, z) -- Where will the starting position be located?
local endingPos = Vector3.new(x, y, z)  -- And the ending?

local inArena = false -- We will start with the player outside the arena right?

function teleport(par1)
    if not inArena then
         -- If the player isn't in the arena then it will be teleported to it
        par1.Character:MoveTo(endingPos)
        inArena = true -- Now the player is in the arena
    else
        -- Otherwise it will be teleported to the spawn
        par1.Character:MoveTo(startingPos)
        inArena  = false -- Now in the spawn :P
    end
end

Finally, call the function wherever you want, just remember, if you call the function once, you then need to recall it again for teleporting back to spawn, be aware on how many times you call this function!

Ad
Log in to vote
0
Answered by
Hybric 271 Moderation Voter
10 years ago

Put this script into the part that is touched, and name the part that the players teleports on "Exit" (NAME THE PART THAT THE PLAYER WILL BE TELEPORTED ON: "Exit")

function h(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h ~= nil) then
h.Parent:MoveTo(Workspace.Exit.Position + Vector3.new(0, 4,0))
end
end

script.Parent:Touched:connect(h)

Answer this question