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

How do I create a chat-activated teleport within a place?

Asked by 5 years ago

I've been trying to create a script that teleports a player to a specific coordinate after typing a keyword in the chat. Unfortunately I haven't had any luck. Can someone please help me out? Thanks so much!!!

2 answers

Log in to vote
1
Answered by
Velsity 218 Moderation Voter
5 years ago
Coordinate = CFrame.new(14.3, 0.5, 37.4)

game.Players.PlayerAdded:Connect(function(P) -- Check when a new player joined
    P.Chatted:Connect(function(Msg) -- Check if person chatted
        if string.lower(Msg) == "lol" then -- Check if they chatted our keyword "lol"
            P.Character:SetPrimaryPartCFrame(Coordinate) -- teleport them
        end
    end)
end)

I encourage you to use SetPrimaryPartCFrame instead of setting the CFrame of a part on the player, The coordinate I took was a part position and turned it into a CFrame for it to work.

Ad
Log in to vote
-1
Answered by 5 years ago

Roblox Player Chatted

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local tpCommand = "/teleport "

local function onPlayerChatted(player, message, recipient)
  if message:sub(1, tpCommand:len()):lower() == tpCommand:lower() then
    game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))
  end
end

local function onPlayerAdded(player)
  player.Chatted:Connect(function (...)
  onPlayerChatted(player, ...)
  end)
end

for _, player in pairs(Players:GetPlayers()) do
  onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)

Just ripped and re-wrote, you need to replace the CFrame with yours obviously.

0
You should use SetPrimaryPartCFrame instead. Theres no need to use :lower() on the tpCommand as it is already lowercase. Velsity 218 — 5y
0
Like I said, I just ripped it straight off the Roblox Website I linked and changed like 3 things Preazy_RBLX -2 — 5y

Answer this question