Teleporting forward script

Hello, i made a script that when you press “V” you will teleport forward at direction you looked at but for some reason my script wont work where and what did i do wrong?

local RS = game:GetService("ReplicatedStorage")
local KCTP = RS:WaitForChild("KingCrimsonTeleport")

KCTP.OnServerEvent:Connect(function(player)
	game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = CFrame.LookVector * CFrame.new(0, 0, 5)
end)

thanks for trying to help

CFrame is the table that contains all the constructors to create instances of the CFrame class. You don’t get the properties of this class from the table alone. You don’t even need the LookVector property.

KCTP.OnServerEvent:Connect(function(player)
    local character = player.Character
    character:SetPrimaryPartCFrame(character:GetPrimaryPartCFrame()*CFrame.new(0, 0, -5))
end)
3 Likes

The correct script was posted (by incapaxx), but the reason it may go haywire is because you’re trying to set the CFrame to the LookVector, when in reality you’d want to see a CFrame to a position.

The reason it still goes through is because a positional value and a LookVector have the same data type; Vector3. Setting a CFrame have to always start with the position, or another CFrame. By applying a LookVector, you’re passing it as a position when it’s actually the Unit measurement for the front face. I hope all of that made sense, if you have any other questions, let me know.