How to get a part through mouse position

How can i get a part through the mouse’s position? I have this script right here:

local tool = script.Parent
local plant = script.Parent.Plant
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

script.Parent.Activated:Connect(function(v)
	local hit = mouse.Hit.Position
	
end)

And i want to know if the mouse’s position hit a part and if so, interact with that part. How can i do that?

Try it as this (referenced from this):

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target then
		--insert your code here for an interaction
	end
end)
3 Likes