Before I start, I am not trying to get the position of a part a mouse has clicked.
Anyhow, I am attempting to find the position of where a mouse has clicked. I am aware that
local ray = camera:ScreenPointToRay(input.Position.X, input.Position.Y, 0)
local part = workspace:FindPartOnRay(Ray.new(ray.Origin, ray.Direction * 500))
exists, though there's a few problems with it.
This script only finds the part of where the mouse has clicked. When I make a script out of this, "part" returns a part, not a position. I could use the position of said part, but it wouldn't be accurate as if I click the tip of, say, baseplate, the position of the baseplate is what it will return and that is not what I want.
If I go a few steps back to "input.Position.X" and "Input.Position.Y", this is only XY but I need a Z.
Ultimately, what I'm trying to achieve is create a part of where said XYZ of clicked is. This is the script I currently have:
local tool = script.Parent.FrontPart
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
UserInputService.InputBegan:Connect(function(input, gpe)
if not gpe and input.UserInputType == Enum.UserInputType.MouseButton1 then
local ray = camera:ScreenPointToRay(input.Position.X, input.Position.Y, 0)
local position = workspace:FindPartOnRay(Ray.new(ray.Origin, ray.Direction * 500)).Position -- this is the previous script but editted
if position then
-- Blah Blah create part here.
end
end
end)
As you can see this will run some issues. Pretend I want to create a part on the surface of baseplate, what will happen instead is that it will create a part in the center of baseplate. Is there a way to locate the position of when the ray collide with the part, and have it return an accurate position?

2 comments
You could make something follow the mouse, so that when they click, that thing is on the mouse.
Im not sure if you can, just a suggestion.