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

why wont mouse.Changed fire?

Asked by 5 years ago
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

0
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 TheGreenSuperman 85 — 5y
0
^^^ There is no "Changed" event. And as mentioned above, Mouse is considered legacy so you might want to use UserInputService or ContextActionService instead. Cousin_Potato 129 — 5y
0
there is a changed event! check the wiki: https://developer.roblox.com/api-reference/class/Mouse jojo8764 -5 — 5y
0
"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. Cousin_Potato 129 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
i actually was using the mouse.Move event earlier, the problem was that everytime a new block appeared in front of my mouse, the event wouldnt fire unless i moved my mouse again. jojo8764 -5 — 5y
0
^ I fixed it so that it repeats as long as the mouse is on the object TheGreenSuperman 85 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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?

0
can i atleast know why the changed event wont work in this script? jojo8764 -5 — 5y
0
according to the roblox wiki it should work jojo8764 -5 — 5y

Answer this question