Hello! I want player to teleport when I type teleport/person229
if msg:sub(1, 9) == "teleport/" and game:GetService("GamePassService"):PlayerHasPass(player, 174527407) then if game.Workspace:FindFirstChild(msg:sub(10)) ~= nil then --I just need help here. How to teleport player? end end
function onChat(player, chat) --We need to create a function so that the script knows what to do. if chat:sub(1,9) == "teleport/" then --If the Vip person says teleport/ then the script will listen. if player.Character:FindFirstChild("Torso") then --Does the torso exist? If not, the player may not exist. for _,v in pairs(game.Players:GetChildren()) do --Let's start looking for his target. if v.Name:sub(1, chat:sub(10):len()):lower() == chat:sub(10):lower() then --[[ Those lines must have been confusing. v.Name is the Name of the player, which we are getting from the loop (for _,v ...). It will check the name to what you said in the chat, example; teleport/m3 It will teleport you to M39a9am3R. The script will go by the partial name.]] if v.Character:FindFirstChild("Torso") then --Does the destination have a Torso? player.Character:MoveTo(v.Character.Torso.Position) --Since the Character is a model, MoveTo will work. --Now, player will spawn right on top of the destination player. end break --End the loop, we found the person, we don't want to go through this again. end end end end end game.Players.PlayerAdded:connect(function(player) --A player has entered, we just fired a event. if game:GetService("GamePassService"):PlayerHasPass(player, 174527407) then --If he has the game pass then start reading his chats. player.Chatted:connect(function(chat) --If he chats, this line of script will fire. onChat(player, chat) --Go to the top of the script for the function. end) end end)
Alright, I guess it was not easy to make. This has not been tested! All the comments of as to how the sections of the script work are in the script itself.
I figured it out here: https://scriptinghelpers.org/questions/11381/how-can-i-make-player-teleport-sloved