Teleport script not working

im making this teleport script, but i cant figure out why its not working

local UserInputService = game:GetService("UserInputService")

function teleport()
	local t = game.Workspace:FindFirstChild("HumanoidRootPart")
	if t == ("HumanoidRootPart") then
	t.CFrame= t.Cframe + (t.CFrame.LookVector * Vector3.new(0,0,-5))
end
	

UserInputService.InputBegan:Connect(function(Key) 
	if Key.KeyCode == Enum.KeyCode.E 
	then
		print("teleport")
			teleport()
		end
		end)
end

can you help me out? Thanks

Hi, I think your code should look like this:

local UserInputService = game:GetService("UserInputService")

function teleport()
	local t = game.Workspace:FindFirstChild("HumanoidRootPart")
	if t and t.Name == ("HumanoidRootPart") then
	   t.CFrame= t.CFrame + (t.CFrame.LookVector * Vector3.new(0,0,-5))
    end
end
	

UserInputService.InputBegan:Connect(function(Key) 
	if Key.KeyCode == Enum.KeyCode.E then
	  print("teleport")
	  teleport()
	end
end)

Hope it helps!

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

function teleport()
	if Players.LocalPlayer.Character and Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
		local t = Players.LocalPlayer.Character.HumanoidRootPart
		t.CFrame= t.Cframe + (t.CFrame.LookVector * Vector3.new(0,0,-5))
	end
end
	

UserInputService.InputBegan:Connect(function(Key) 
	if Key.KeyCode == Enum.KeyCode.E then
		print("teleport")
		teleport()
	end
end)
2 Likes

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