Local Script
local mouse = game:GetService('Players').LocalPlayer:GetMouse()
mouse.Move:Connect(function()
if mouse.Target and mouse.Target.Name == "Target" then
print("NewTarget")
end
end)
connect is considered deprecated (even though it sometimes works) use Connect instead
There are no parameters for the mouse.Move event
While the Changed event is valid for the Mouse, it will not work for this script, which is why we use the mouse.Move event instead.
Check that "mouse.Target" is not nil before using the function (this occurs when pointing it at the sky) otherwise, it will error and break.
EDIT
Based on your above comment, you could try adding this additional function
workspace.ChildAdded:Connect(function()
if mouse.Target and mouse.Target.Name == "Target" then
print("NewTarget")
end
end)
The ChildAdded event should be able to check if the part is different, unless of course the part was already in the workspace?
4 comments
this isn't answering your question, but :connect() is depreciated. use :Connect() instead. Plus, I think I heard the Mouse function is considered a legacy function and should not be used for new works
^^^ There is no "Changed" event. And as mentioned above, Mouse is considered legacy so you might want to use UserInputService or ContextActionService instead.
there is a changed event! check the wiki: https://developer.roblox.com/api-reference/class/Mouse
"Fired immediately after a PROPERTY of an object changes." In other words, "Changed" is not for USER INPUT. Nowhere in the script are you changing mouse properties.