Determine if mouse is in workspace (Plugins)

I am trying to make a plugin for managing my PBR assets, and I need to check if the user is hovering their mouse over a part so I can apply PBR to it. The problem is that if the mouse is outside of the workspace window the mouse position freezes at its last location, which is still inside the workspace window. I need to be able to detect if the mouse is actually inside the workspace window. Anyone got any ideas?

There is a property called Target for the mouse. You set up a property changed then look for the target. If there is a target it will put out the part, if there is no target it will return nil.

Target also gets frozen. if the player moves the mouse out of the workspace window the target always stays as the last target, and doesn’t change.

EDIT: Here’s the code I used to test this


local plugin = PluginManager():CreatePlugin() 
local mouse = plugin:GetMouse()
while wait() do print(mouse.Target) end

With the help of a friend I found a solution, so disregard this for now. Apparently there is an InputEnded event that can fire for MouseMovement, and that is what signals that the user has stopped moving their mouse in the screen.