Help with CFrames

I want a line of code that uses this command:


I think it’s useful for my code but I can’t seem to get the right thing

my code:

local test =,RootPart.CFrame.Y,RootPart.CFrame.Z)
local newCframe = CFrame:PointToWorldSpace(test)

and the error is attempt to call a nil value


why are you making a new vector3 with the positions individually? try inputting the position directly like so

local newCframe = CFrame:PointToWorldSpace(RootPart.Position)

This might not solve the issue but just a tip

changed that but same message appears

Your issue lies in the fact that it takes a CFrame object, not the class. It should look more like

local cf =,0,10)
local v3 =,0,1)
local newPos = cf:PointToWorldSpace(v3)
-- 11, 0, 11

if that’s the problem why at this code

part.Size =,1, magnitude)
local pos =,0,-50)
part.CFrame =,RootPart.CFrame.LookVector)
part.CFrame = part.CFrame:PointToWorldSpace(pos)

the output is invalid argument #3 (CFrame expected, got Vector3)

it refers this line:
part.CFrame = part.CFrame:PointToWorldSpace(pos)

The method returns a vector3 not a CFrame so that’s why you’re getting the error.

What are you trying to do? Maybe we can help more if you elaborate. Right now it seems like you’re just throwing methods you don’t understand at the wall and seeing what sticks.

I’m trying to visualize a ray that i cast
lemme give you some more data

and the whole script:

local weapon = script.Parent
local enabled = true
local dazed = game.ServerStorage.KatanaDiversity.Dazed2
local rdazed = game.ServerStorage.KatanaDiversity.RevertedDazed
local Char = weapon.Parent.Parent
local RootPart = Char.HumanoidRootPart

local IL = {}


local RAY =, RootPart.CFrame.LookVector * 100)
local RayPos,HitPos = workspace:FindPartOnRayWithIgnoreList(RAY, IL, false, true)
local Hits = {}
table.insert(Hits, HitPos)
for index,Items in ipairs(Hits) do
	if not Items then
		print("no items")
	HIt = Items
local part ="Part")
part.Anchored = true
if HIt then
	magnitude = (RootPart.Position - HIt).Magnitude
	magnitude = 100
part.Size =,1, magnitude)
local pos =,0,-50)
part.CFrame =,RootPart.CFrame.LookVector)
local newpos = part.CFrame:PointToWorldSpace(pos)
part.CFrame =,RootPart.CFrame.LookVector)
part.CanCollide = false
part.Parent = RootPart

So you’re just trying to draw a line between the ray and the hit position? No need for any conversion to/from world space everything you need is already converted.

local PART ="Part")
PART.Size =, 0.1, 0.1)
PART.Anchored = true
PART.CanCollide = false
PART.TopSurface = Enum.SurfaceType.Smooth
PART.BottomSurface = Enum.SurfaceType.Smooth
PART.Material = Enum.Material.SmoothPlastic

local function drawLine(a, b)
	local line = PART:Clone()
	line.CFrame = + b)/2, b)
	line.Size =, 0.1, (b - a).Magnitude)
	line.Color =, 1, 0)
	return line

-- example use

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local mouse = game.Players.LocalPlayer:GetMouse()

local lastLine = nil

	local ray =, (mouse.Hit.p - handle.Position).Unit*1000)
	local hit, pos, normal = workspace:FindPartOnRay(ray, tool.Parent)
	if (lastLine) then
	lastLine = drawLine(ray.Origin, pos)
	lastLine.Parent = tool


well that’s the solution for the main goal, but the solution for this topic was given earlier

Thanks for all the help @EgoMoose, @SorxtaKanda
It meant a lot,

1 Like