Position is not a valid member of Vector3

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

  1. What do you want to achieve?
    I want to shoot a raycast to the player’s mouse
  2. What is the issue?
    It looks as if it thinks the hit is a Vector3
  3. What solutions have you tried so far?
    I tried removing the .Position after the hit but it said Unit is not a valid member of CFrame

Here is my code

local function castRay(hit)
	local orgin = script.Parent.Handle.Position
	local Stop = (hit.Position - orgin).Unit * 500
	local result = workspace:Raycast(orgin, Stop, params)
	if result then
		local target = result.Instance
		if target.Parent then
			local position = result.Position
			return castRay(position)
		end
	end
end

script.Parent.Shoot.OnServerEvent:Connect(function(player, Hit)
	local Attachment0 = Instance.new("Attachment")
	Attachment0.Parent = Target
	Attachment0.Position = castRay(Hit)
end

If you know how to fix this please let me know!

You are giving a Vector3 instead of an Instance, and Vector3 doesnt inherit Position

Do you have an alternative that I could use?

If you are trying to get the Instance from the Raycast, it would be result.Instance instead of result.Position

local target = result.Instance
if target.Parent then
	return castRay(target) -- returns the Instance
end
1 Like