Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I make a tool that names a part?

Asked by 10 years ago

Yet, another question. This is a simpler one though. How would I make a hopperbin that finds the name of a part when clicked on? I use mouse.Hit but it doesn't seem to work. Here's my script.

mouse.Button1Down:connect(
function(target)
    target = mouse.Hit
    print(target.Name)
end
)

The error(I'm not sure if this is necessary)

19:57:52.204 - Name is not a valid member
19:57:52.205 - Script 'Players.Player1.Backpack.Extract.Script', Line 9
19:57:52.205 - Stack End
19:57:52.206 - Disconnected event because of exception
20:00:43.544 - Auto-Saving...

1 answer

Log in to vote
1
Answered by 10 years ago

First off, you have a parameter in your function called "target", but Button1Down doesn't return anything. Second, mouse.Hit doesn't return an object, it returns a CFrame. This would be the correct code:

mouse.Button1Down:connect(function() --connects the function to the Button1Down event
    if mouse.Target then --Makes sure the Target exists
        print(mouse.Target.Name) --Prints the Target's name
    end
end)

Hope this helped!

Ad

Answer this question