How do I make it so when I hover over an object it underlines it

Hi I want to know how can I make it so when I hover over an object it underlines it like in the following picture of mining simulator:


Thank for taking your time and reading this.

You’ll want to use SelectionBox to highlight the box. Other than that, you can get the block to highlight by getting the mouse’s screen position, getting the unit ray (by using Camera:ViewportPointToRay), and casting the ray with only the boxes you want to be highlightable provided in the raycast parameters and whitelisted.

local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local camera = Workspace.CurrentCamera

function getSelectedPart(partHolder)
    local screenPoint = UserInputService:GetMouseLocation()
    local unitRay = camera:ViewportPointToRay(screenPoint.X, screenPoint.Y)

    local raycastParams = RaycastParams.new()
    raycastParams.FilterDescendantsInstances = { partHolder }
    raycastParams.FilterType = Enum.RaycastFilterType.Whitelist

    local raycastResult = Workspace:Raycast(
        unitRay.Origin,
        unitRay.Direction * MAX_DISTANCE,
        raycastParams
    )
    return raycastResult and raycastResult.Instance
end

oh okay tysm :slight_smile: really appreciate it!

1 Like