✓ Accepted answer
The code is a lot simpler than it looks, I have used a LocalScript inside StarterPlayer > StarterCharacterScripts to actually make it work & with the size constraint as you mentioned.
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local selection = Instance.new("SelectionBox");
selection.Color3 = Color3.new(0.6, 0.6, 0.6)
selection.Parent = script.Parent;
mouse.Move:Connect(function()
local target = mouse.Target;
if not target then
selection.Adornee = nil;
elseif target and target.Size.Y >= 8 then
selection.Adornee = target;
end
end)
It is pretty self-explanatory, every part that the mouse targets and has anY coordinatebigger than the one defined in the code will be selected with an adornee. Take care that if there is no target or if it doesn't exist it won't actually add an Adornee. If you want to filter the parts that can be selected you can also add a table and filter by name.
Hope this helped!
Modified ~
As you want it to only work for a specific part, you can actually identify the part by the actual name, in this case we have the part named** "Pizza"** that will only get selected if it has an Y coordinate higher than 8. Altough if you want to add more parts it would be more efficient if you actually added a table with the parts that you especifically want to get adorneed.
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local selection = Instance.new("SelectionBox");
selection.Color3 = Color3.new(0.6, 0.6, 0.6)
selection.Parent = script.Parent;
mouse.Move:Connect(function()
local target = mouse.Target;
if target and target.Size.Y >= 8 and target.Name == "Pizza" then
selection.Adornee = target;
else
selection.Adornee = nil;
end
end)
Hope this helped you, once again!
2 comments
Is this script inside a part in the workspace, or inside the startergui?
Inside a part in the workspace.