Help with CFrames

I want a line of code that uses this command:

CFrame:PointToWorldSpace()

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

my code:

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

and the error is attempt to call a nil value

Thanks,
Tem

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 = CFrame.new(10,0,10)
local v3 = Vector3.new(1,0,1)
local newPos = cf:PointToWorldSpace(v3)
print(newPos)
-- 11, 0, 11

if that’s the problem why at this code

part.Size = Vector3.new(1,1, magnitude)
local pos = Vector3.new(0,0,-50)
part.CFrame = CFrame.new(RootPart.Position,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 = {}

print("Check1")

local RAY = Ray.new(RootPart.Position, RootPart.CFrame.LookVector * 100)
local RayPos,HitPos = workspace:FindPartOnRayWithIgnoreList(RAY, IL, false, true)
print("Check2")
local Hits = {}
table.insert(Hits, HitPos)
for index,Items in ipairs(Hits) do
	if not Items then
		print("no items")
	end
	HIt = Items
	print(Items)
end
local part = Instance.new("Part")
part.Anchored = true
if HIt then
	magnitude = (RootPart.Position - HIt).Magnitude
else
	magnitude = 100
end
part.Size = Vector3.new(1,1, magnitude)
local pos = Vector3.new(0,0,-50)
part.CFrame = CFrame.new(RootPart.Position,RootPart.CFrame.LookVector)
local newpos = part.CFrame:PointToWorldSpace(pos)
part.CFrame = CFrame.new(newpos,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 = Instance.new("Part")
PART.Size = Vector3.new(0.1, 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 = CFrame.new((a + b)/2, b)
	line.Size = Vector3.new(0.1, 0.1, (b - a).Magnitude)
	line.Color = Color3.new(1, 1, 0)
	return line
end

-- example use

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

local lastLine = nil

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

3 Likes

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,
Tem

1 Like