If I were to to do this:
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
function DownClick()
print (mouse.Target.Name)
end
mouse.Button1Down:connect(DownClick)
Would it print out the name of the part you clicked?
If I were to to do this:
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
function DownClick()
print (mouse.Target.Name)
end
mouse.Button1Down:connect(DownClick)
Would it print out the name of the part you clicked?
Yes, this will work.
mouse.Target will be the part (not model) that the mouse is hovering over, or nil if the mouse is not hovering over any part (e.g., you click in the sky).
The "or nil" part is very important to remember. The script you have will break if you click in the sky. Always check that mouse.Target exists:
if mouse.Target then
print(mouse.Target.Name)
else
print("Sky!")
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
Yes. And you could quite easily have tested that yourself in about five seconds.
Could I really have when i'm posting from a raspberry pi, and don't currrently have anything to test it on?
And also if you click on a part in a model, do you click on the model or the part?
The Target property will either return the BasePart that the mouse is hovering over or nil.
Thanks