[BUG?] Using GetPropertyChangedSignal on mouse.Target

I want to reduce my use of loops in my scripts. I am working on a radar gun for my game, and instead of running a constant loop to check the mouse.Target, I want to use mouse:GetPropertyChangedSignal("Target"). It hasn’t been working, so I am not sure if I am doing something wrong or if it just doesn’t work. I went into the object browser and the function is listed under mouse, so I am unsure.

Any help you can give would be greatly appreciated.

2 Likes

Do you mind posting the full event connection including the function? It’s hard to go off of what you posted.

1 Like
	Clone = script.Radar:Clone()
	Clone.Parent=player.PlayerGui
	mouse:GetPropertyChangedSignal("Target"):Connect(function()
		print'target'
		local target = mouse.Target
		if target~=nil then
			local rawSpeed = math.floor(target.Velocity.Magnitude)
			if rawSpeed>0 then
				local speed = rawSpeed*ac6MPHRate
				Clone.Speed.Text = "Speed Clocked:\n"..speed
			end
		end
	end)

Target is a BasePart though, not Vector3.

The age old question, but have you gotten errors?

My bad, I got confused with Target and Hit.

Just running this code in studio doesn’t work

local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse:GetPropertyChangedSignal("Target"):Connect(function()
	print(Mouse.Target)
end)

So I’m assuming you can’t get a changed event for Target.

Nope :confused: Would be helpful if I did

You could use the Mouse.Move event

1 Like

According to my breif testing I came to the same conclusion as the rest of you that :GetPropertyChangedSignal and .Changed does not work.

So what I would recommend is you use mouse.Move then check if mouse.Target has changed

local target
mouse.Move:Connect(function()
    if mouse.Target then
       if target ~= mouse.Target then
            target = mouse.Target
            -- do rest of code
       end
    end
end)

I decided I am just going to use RunService.RenderStepped. Seems to be the only option. I am not going to use mouse.Move though because if you keep your mouse stationary, and the target changes, it will not fire. Thank you guys for your help :))

Okay you can use the same method I posted with .RenderStepped

I know this was a while ago, but I’d like to bump this again. Is it a bug, or intentional?

I don’t think it is a bug , check this out : https://devforum.roblox.com/t/is-there-an-event-for-when-mouse-target-changes/39923/4

However you can easily find a workaround for this by using UserInputService or constantly checking it,totally based on your case.

2 Likes

that :GetPropertyChangedSignal doesn’t fire? Not a bug. I suspect that would fire basically the same as RenderStepped, it could be just that also they forgot. there is the mouse.Move like they mentioned above though. Not sure why you didn’t use that, it’s basically what you mentioned.

Yeah just that Mouse.Move fires way more frequently than checking when the Target changes.

1 Like

Hey everyone, I would like to bump this topic and see if anyone could find a solution.

Still found no solution, and the documentation does not provide any information on this (or as to why it should not work). Perhaps someone could mark this as a bug?

You cannot use GetPropertyChangedSignal on all properties of an instance.

As others suggested, using UserInputService to find out if the mouse is moving and therefore checking its Target would be a solution. Otherwise using a loop might be an option.

Documentation says this:

The event returned by this method does not fire for physics-related changes, such as when the CFrame, AssemblyLinearVelocity, AssemblyAngularVelocity, Position, or Orientation properties of a BasePart change due to gravity. To detect changes in these properties, consider using a physics-based event like RunService.PreSimulation.

It does not mention mouse however.

I am only trying to make an event of when the mouse.Target changes. For instance, a player might move their mouse, but the target could be the same. The opposite is true, such as if the target part moves away from the mouse while the mouse does not move.

Additionally, Roblox lists the GetPropertyChangedSignal function as a working function under the mouse instance, but not for the baseparts I previously mentioned.