I want to make it so when a player touches a certain part they can type for example: teleport 1 and the would be teleported to another place in my universe, here is the error I am getting: Workspace.Model.TeleportPad.Script:8: attempt to index field 'Chatted' (a nil value)
Here is my script so far:
local TeleportService = game:GetService("TeleportService")
local floor1Id = 518904899
local floor2Id = 518905949
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
local player = hit.Parent:findFirstChild("Humanoid").Parent.Name
player.Chatted:connect(function(msg)
if msg:sub(1,8) == "teleport" then
if msg:sub(10) == 1 then
TeleportService:Teleport(floor1Id, player)
elseif msg:sub(10) == 2 then
TeleportService:Teleport(floor2Id, player)
end
end
end)
end
end)

2 comments
can you please put this in a code block.
Yeah