SelectionBoxes on mouse selection?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make it so whatever part your mouse is hovering over gets a local SelectionBox.

  2. What is the issue? Include enough details if possible!
    I don’t know how to make it

  3. What solutions have you thought of so far?
    I tried making my own, then looking on the DevForum, but could not find anything.

I’m not too sure exactly what you are trying to accomplish, but here is a good start to it :

local mouse = game.Players.LocalPlayer:GetMouse() -- Getting the local player's mouse

mouse.Move:Connect(function(movement) -- When the players mouse moves on the screen
    local target = mouse.Target -- The target of the mouse (what the players mouse is hovering over)
    local selection = Instance.new("SelectionBox", target) -- A new instance of a selection box
    selection.Adornee = target -- Setting the adornee (basically the parent of the selection box) to the mouse's target
    selection.Color3 = Color3.new(0, 1, 0.974182) -- **Put whatever Color3 value you want here**
    mouse.Move:Connect(function(movement2) -- Making another move function to check if the mouses target has been changed
	    local target2 = mouse.Target
	    if target2 ~= target then -- Checking exactly if the new target of the mouse is the same as last ones
		    selection:Destroy() -- Destroying the selection box if it isn't the same as the last target
	    end
    end)
end)

Make sure to put this code in a Local Script, inside of StarterCharacterScripts. If you want me to expand on this code (only making the selections when in certain areas or only while doing certain things) let me know and I can help out more.

3 Likes