This script is meant to have a selectionbox appear over a block if your mouse is aimed at that block and that block is a certain height. This is the script:
while wait() do if script.Parent.Size.Y >= 8 then local player = game.Players.LocalPlayer local mouse = player:GetMouse() local selection = Instance.new("SelectionBox") selection.Color3 = Color3.new(0.6,0.6,0,6) selection.Parent = player.PlayerGui mouse.Move:connect(function() local target = mouse.Target if not target then selection.Adornee = nil elseif target == script.Parent then selection.Adornee = target else selection.Adornee = nil end end) end
This works without the size constraint, how do I fix it to work under the size constraint. Do I use and
?
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(); -- // Selection Creation local selection = Instance.new("SelectionBox"); selection.Color3 = Color3.new(0.6, 0.6, 0.6) selection.Parent = script.Parent; -- // Event mouse.Move:Connect(function() local target = mouse.Target; if not target then selection.Adornee = nil; elseif target and target.Size.Y >= 8 then -- Filters if target exists & its height is higher than 8. selection.Adornee = target; end end)
It is pretty self-explanatory, every part that the mouse targets and has anY coordinate
bigger 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(); -- // Selection Creation local selection = Instance.new("SelectionBox"); selection.Color3 = Color3.new(0.6, 0.6, 0.6) selection.Parent = script.Parent; -- // Event mouse.Move:Connect(function() local target = mouse.Target; if target and target.Size.Y >= 8 and target.Name == "Pizza" then -- Filters if target exists & its height is higher than 8 and with name "Pizza". selection.Adornee = target; else selection.Adornee = nil; end end)
Hope this helped you, once again!