Help with PointToObjectSpace

You can write your topic however you want, but you need to answer these questions:

  1. Recently, i found a script that sets the camera to the head

  2. I get this error: PointToObjectSpace is not a valid member of Vector3

  3. I tried using CFrame instead of Vector3 but it says: expected Vector3 got CFrame

local RunService = game:GetService("RunService")

if not game.Players.LocalPlayer.Character then
	return
elseif game.Players.LocalPlayer.Character:WaitForChild("Humanoid") then
	if not game.Players.LocalPlayer.Character:WaitForChild("Head") then
		return
	end
end

RunService:BindToRenderStep("TrackHead", Enum.RenderPriority.Camera.Value, function(deltaTime)
	if not game.Players.LocalPlayer.Character then
		return
	end
	local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
	if Humanoid then
		if not game.Players.LocalPlayer.Character:WaitForChild("Head") then
			return
		end
		Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0, 1.5, 0):PointToObjectSpace(game.Players.LocalPlayer.Character:WaitForChild("Head").Position), deltaTime * 20)
	end
end)

Any help is very appreciated.

1 Like

The error is returning because you’re firing PointToObjectSpace on the Vector3 instead of the CFrame. All you should need to do to fix it is put parentheses around game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0, 1.5, 0)

I did a rewrite of the script that condenses it a decent bit, which should be placed in StarterCharacterScripts:

local RunService = game:GetService("RunService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")

local head = character:WaitForChild("Head")

RunService:BindToRenderStep("TrackHead", Enum.RenderPriority.Camera.Value, function(deltaTime)
	humanoid.CameraOffset = humanoid.CameraOffset:Lerp((rootPart.CFrame + Vector3.new(0, 1.5, 0)):PointToObjectSpace(head.Position), deltaTime * 20)
end)
2 Likes

Yoo, tysm! I don’t know how many other things I tried to do this effect, but now, thanks to you, it works :grinning: :grin:

1 Like

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