local mouse = game:GetService('Players').LocalPlayer:GetMouse() mouse.Changed:connect(function(x) print(".") if x == "Target" then print("NewTarget") end end)
the mouse.Changed event wont fire and doesnt even print any "."
does it have anything to do with me using a local script? help
I did a bit of testing, and I came up with the following code. I use the ".Move" event instead of ".Changed" because it seems to work better, and it checks if the part the mouse is pointing at an object. If so, it checks the part's name, and if the part's name is "Target" it prints "NewTarget".
local mouse = game:GetService('Players').LocalPlayer:GetMouse() mouse.Move:Connect(function(x) if mouse.Target then if mouse.Target.Name == "Target" then repeat print("NewTarget") wait() until mouse.Target.Name ~= "Target" end end end)
if this helped, don't forget to accept this answer :D
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?