Trying to make a range limit on how far something can be placed. This returns 'CFrame expected, got Vector3.' - 12

local part = game.ReplicatedStorage.Part
local uis = game:GetService("UserInputService")
local char = script.Parent
local m = game.Players.LocalPlayer:GetMouse()


uis.InputBegan:Connect(function(input,process)
	if not process and input.UserInputType == Enum.UserInputType.MouseButton1 then
		local ray = Ray.new(char.HumanoidRootPart.Position,(char.HumanoidRootPart.CFrame.p - m.hit.p).unit * -200)
		local clone = part:Clone()
		clone.Parent = workspace
		clone.CFrame = ray.Direction.unit *200
	end
end)

2 comments

0

ray.Direction.unit is a Vector3 value. Multiplying it by 200 results in another Vector3 value. clone.CFrame needs to be a CFrame value. CFrame values are position with direction, but you're only providing position.

0

Instead do clone.CFrame = CFrame.new(char.HumanoidRootPart.Position + m.hit.p) / 2, m.hit.p) to get a CFrame with a position half way between the character and mouse, pointing toward the mouse.