Answers for "how to select object on hover in roblox"

0

how to select object on hover in roblox

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)
Posted by: Guest on January-29-2022

Browse Popular Code Answers by Language