Selection Boxes on HumanoidRootPart

I’m currently making a tool and trying to integrate it with selection boxes, but I’m stumped.

I’m trying to add a feature, to where when you hover over someone’s HumanoidRootPart a selection box appears, but I don’t know how to go about doing it, as in, I don’t know a good way to detect whether the user’s mouse is hovering over the part.

Does anyone know how to go about this?

Check out the functions Camera:ViewportPointToRay() and Camera:ScreenPointToRay(). These return a ray with origin and direction property. You can use it in a new Ray then multiply direction by how far the camera can go to.

InputObjects have a position so you can use UserInputService then use an InputChanged connected function to use the camera functions with the InputObject position X and Y value like this:

camera:ViewportPointToRay(input.Position.X, input.Position.Y)

Then use that towards a raycast method and it’ll work as expected.

If you need more, I will try to edit tomorrow and add more.

1 Like

Yes please, tomorrow can you explain a bit more about it, thank you for your advice.

A simple way of doing this would be using player:GetMouse()

local mouse = game:GetService("Players").LocalPlayer:GetMouse()

-- Fired when the player moves their mouse
    if mouse.Target ~= nil then
        if mouse.Target.Name == "HumanoidRootPart" then
            -- Show selection box
            -- Hide selection box
1 Like

I guess that works too, never thought of doing that… Guess I over-complicated everything! Thanks!