Help on a command

I wanted to do a command that teleports the player to a place and I don’t know how to script…Yeah… I tried looking up tutorials and stuff but ended up with this mess:

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == “PLACEHOLDER” then
game:GetService(“TeleportService”):Teleport(113490953932043,Player)
end
end)
end)

Please help me!

are you getting an errors or warns in the output? also where is the script, where did you place the script and what type of script is it?

Uhhhh How do you see errors? Sorry I NEVER script so I don’t know much.

at the top of the editor there is a tab called “view”, click on that and look for a button that says “output”

I think this is what you’re talking about:


Also I updated the post to make the script more visible.

Player doesnt exist
You have player only

--!strict
--!optimize 2
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")

Players.PlayerAdded:Connect(function(player:Player):()
	player.Chatted:Connect(function(message:string):()
		if message == "PLACEHOLDER" then
			TeleportService:Teleport(113490953932043,player)
		end
	end)
end)
1 Like

Thank you very much! Have an amazing day!

1 Like

Is this from a LocalScript? If so, then unfortunately .Chatted had been disabled for the client. You’ll have to do this from a server Script.

If I may as well, I suggest applying some error handling in case the teleport fails.

local PlaceToTeleport = 113490953932043
local WhatToSay = "PLACEHOLDER"
local MaxRetries = 3


local TeleportService = game:GetService("TeleportService")
local PlayersService = game:GetService("Players")
local PlayerRetries = {}
local function InititateTeleport(plyr)
	pcall(TeleportService.TeleportAsync, TeleportService, PlaceToTeleport, {plyr}) -- Attempt the teleport, run the code in a protected call.
end

PlayersService.PlayerAdded:Connect(function(plyr)
	PlayerRetries[plyr.UserId] = PlayerRetries[plyr.UserId] or 0
	plyr.Chatted:Connect(function(msg)
		if msg == WhatToSay then
			InitiateTeleport(plyr)
		end
	end)
end)

TeleportService.TeleportInitFailed:Connect(function(plyr, reason, errmsg)
	if reason ~= Enum.TeleportResult.Success and reason ~= Enum.TeleportResult.IsTeleporting then
		if PlayerRetries[plyr.UserId] <= MaxRetries then -- Give them a few tries to teleport.
			InititateTeleport(plyr) -- Attempt the teleport again.
			PlayerRetries[plyr.UserId] = PlayerRetries[plyr.UserId] + 1 -- Increment the amount of tries by 1.
		else -- Did they still not teleport?
			warn(errmsg) -- Output the error.
		end
	else -- Did they manage to teleport?
		PlayerRetries[plyr.UserId] = nil -- Clean up their old reference if they had.
	end
end)

Hope this helps ya!

EDIT I just learned there’s actually a TeleportAsync method! I re-adjusted the code for it.
TeleportService # TeleportAsync | Documentation - Roblox Creator Hub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.