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.
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)
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 :))
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.
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.
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.