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

How Can I Make Player Teleport?

Asked by 10 years ago

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
0
Is this your entire script? M39a9am3R 3210 — 10y
0
No vincius0000 0 — 10y
0
Actually, never mind, this is fairly easy. I'll make it. M39a9am3R 3210 — 10y

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago
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.

Ad
Log in to vote
0
Answered by 10 years ago

I figured it out here: https://scriptinghelpers.org/questions/11381/how-can-i-make-player-teleport-sloved

Answer this question