Find Where The Part Is I Clicked

At the moment I’m using Mouse1Down in a localscript to find out what part the player is clicking, passing it through a remoteevent and having the script that listened for it print the name of that part. This works perfect.

My problem is I need to be able to locate that part to alter it using the script, how can I do that?

Have you tried mouse.Target? It’s the object in 3D space the mouse is pointing to.

To find the location of the part you can just get It’s Position property, would be something like this:

mouse.Button1Down:Connect(function()
	if mouse.Target and mouse.Target.Parent then
		print(mouse.Target.Position)
	end
end)

That would get the parts actual position though would it not, what I need to be able to get is the part itself in Workspace so for example at the moment I’m making sure to have each part inside a Model in workspace and then I’m passing through 2 values, the first being the mouse.Target.Name and the second being the mouse.Target.Parent.Name, first one being defined to “Target” and the second being defined to “Location” in the script itself, then I use game.Workspace:FindFirstChild(Location):FindFirstChild(Target) to obtain the part. This way works I’m just curious if there is perhaps a more efficient way of doing it?

You should be able to pass the instance as an argument into ur remote event instead of the name. That way the serve script knows exactly which part you’re referring to.

remoteEvent:FireServer(part)

LOL. Thanks, I never once thought to try that because I believed it wouldn’t work and that it couldn’t be that simple. Cheers for the help!

1 Like