Create a Command to Teleport Someone to a Location

The body of your command should be something along the lines of

function teleport(from, to)
     from.Character:SetPrimaryPartCFrame(
        to.Chatacter:GetPrimaryPartCFrame() * CFrame.new(
          Vector3.new(5,0,5))
end

Here’s it integrated with the admin system I provided:


Commands.to = function(Sender,Arguments)
 teleport(Sender, Arguments[1])
end

Commands.bring = function(Sender,Arguments)
 teleport(Arguments[1], Sender)
end

Commands.tp = function(Sender,Arguments)
 teleport(Arguments[1], Arguments[2]
end

ignore the messy code :eyes:
Let me explain what this function does:

  • It moves from to the user to
  • We then offset this by 5 studs (X and Z) to stop clipping.

Some things you can do to make it better:

  • Implement checks (make sure to/from has a character or that the arguments were provided)
  • Tweak the offset
  • Respond to the command (eg using a RemoteEvent and ChatMakeSystemMessage)

(For more advanced programmers), I’d suggest using Cmdr by @evaera; it’s a great command system and is used by many top devs and has great reviews from top devs too.

I’d suggest looking into it, but it by no means is for novice scripters (or you risk having issues or security problems)

2 Likes