Teleporting not working

I’m trying to make it where when a player says a certain phrase they will be teleported somewhere.

Right now I have a script in ServerScriptService:

local Players = game:GetService("Players")
local TouchDestination17 = game.Workspace:WaitForChild("TouchDestination17")

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == "/e hi" then
			
			Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").CFrame = TouchDestination17.CFrame
			
		end
	end)
end)

I think everything is okay except it gives me an error:

ServerScriptService.Script:8: attempt to index nil with ‘Character’

Thanks.

1 Like

You cannot use the LocalPlayer in a ServerScript.
Instead, all you should have to do is player.Character instead of Players.LocalPlayer.Character.

1 Like
local TouchDestination17 = game.Workspace:WaitForChild("TouchDestination17")

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == "/e hi" then
			
			player.LocalPlayer.Character = TouchDestination17.CFrame
			
		end
	end)
end)
1 Like

Hopefully this will help. :slight_smile:

local PhraseAnswer = "/e hi"
local Place = 1234567 --Place ID

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message == PhraseAnswer then
       		game:GetService("TeleportService"):Teleport(Place, Player)
        end
    end)
end)
1 Like

Thanks! It works. Also thank you too everyone else as well.

1 Like