Using GetPropertyChangedSignal on mouse

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.

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

	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.

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