Teleporting with lua

I don’t even know if it is possible, but can you teleport one player to another with server side lua (in a gamemode)?

ply:SetPos(ply2:GetPos() + Vector(0,0,50))

~Edited (Thanks Salads, Vampired)

It’s ‘SetPos’.

and ‘GetPos’


Oh shit I shouldnt let open pages while doing other things :rofl:

thanks. That works. However, I want to place the person where the crosshair is and ply:GetShootPos() puts them inside my head, which isn’t right. It returns a Normalized vector, so I assume that I want to un-normalize it because a normalized one “shows” motion.

I think you’re looking for ply:SetPos(ply:GetEyeTrace().HitPos)

Just don’t look at a wall when you’re teleporting them.

thanks. is there an easy way to do checking if that point would spawn someone inside a wall? maybe someone already has something written. if there isn’t it isn’t a big deal. just curious.

Something like.


Didnt test it though!

unfortunately that doesn’t work. that just puts the person at the origin of the map.


also is there a way to spawn behind someone? I guess it would involve figuring out what direction the person is facing, but again, I hope there is some sort of method I am just missing.

local trace = ply:GetEyeTrace()
ply:SetPos(trace.HitPos + trace.HitNormal*48)


local ang = ply1:GetForward()*-48
ply2:SetPos(ply1:GetPos + ang)

perfect. thank you very much.

Actually, the second one I posted should probably be:

local ang = Angle(0, ply1:GetAngles().y, 0)
ang = ang:Forward()*-48
ply2:SetPos(ply1:GetPos() + ang)

So there’s no vertical offset or anything.

even better!

util.IsInWorld( player:GetPos() ) (NOTE: This returns the opposite of what you would expect so if the pos is in world it will return false :I)