diff --git a/lib/debugger/mouseHighlight.lua b/lib/debugger/mouseHighlight.lua index 7192486..019bb22 100644 --- a/lib/debugger/mouseHighlight.lua +++ b/lib/debugger/mouseHighlight.lua @@ -2,6 +2,19 @@ local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local RunService = game:GetService("RunService") +function getInstanceOnMouse() + local camera = workspace.CurrentCamera + if not camera then + return + end + + local mouseLocation = UserInputService:GetMouseLocation() + local ray = camera:ScreenPointToRay(mouseLocation.X, mouseLocation.Y) + + local result = workspace:Raycast(ray.Origin, ray.Direction * 1000) + return result and result.Instance +end + local function mouseHighlight(debugger, remoteEvent) if not RunService:IsClient() then error("Hovering can only be checked on the client") @@ -10,10 +23,9 @@ local function mouseHighlight(debugger, remoteEvent) local lastSent, setLastSent = debugger.plasma.useState() if UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) then - local mouse = Players.LocalPlayer:GetMouse() - local instance = mouse.Target + local instance = getInstanceOnMouse() - if mouse.Target then + if instance then local id while instance.Parent do id = instance:GetAttribute(debugger:_isServerView() and "serverEntityId" or "clientEntityId")