Alright.
The first thing that I noticed is that mouse.Hit.p gets the position of the mouse. What you were essentially trying to do is find an object that is equal to a position, which you can't do.
Secondly, you got mouse.Hit.p at the start of the script. Once the script is ran, 'tar' is defined and will never change.
Thankfully for you, the mouse has a property called 'Target', which is the part the mouse is currently on top of.
I rewrote some stuff, and here's what I came out with.
01 | local tool = script.Parent |
02 | local mouse = game.Players.LocalPlayer:GetMouse() |
04 | local function Trans(object) |
05 | object.Transparency = object.Transparency - 0.2 |
08 | tool.Activated:Connect( function () |
09 | local tar = mouse.Target |
10 | if tar.Name = = "BOBJECT" then |
**By the way, the reason you were getting an error was because whenever the mousebutton was pressed, it fired the Trans function (line 21). Since tar was already defined, and was probably nil, the function had to change the transparency of a nil value, which it can't do.
(tool.Activated is just a more convenient mouse.Button1Down for tools that fires whenever the mouse button is pressed and the tool is equipped)