Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making this script a teleport command?

I am having some issues with this. Does anyone see why it will not work? I am not getting any output.


 
function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end
 
function onChatted(message, player)
    if message:sub(1, 5) == "to/"  then
        victim = findPlayer(message:sub(6))
         player.Character.Torso.CFrame = victim.Character.Torso.CFrame

        end
    end
 
 
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

1 answer

✓ Accepted answer

Sub takes 1 argument, and then an optional second (when called from the string itself. If using the string.sub method, that's a different story). The first should be where to start, and the second where to end. It will give you the string from that "range".

I suggest changing :sub(1, 5) to :sub(1, 3) and :sub(6) to :sub(4) That should fix it

This discussion is preserved as it was. New answers, comments, and votes are closed.