Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to put a selection box only around one part?

Asked by 10 years ago

Is there a way to put a selection box only around one part when the players mouse is in front of it... The wiki shows how to put a selection box around every part but I want it to do it for only one part So if it was over a players torso It would add a selection box around it.. I dont want to request I just want an Idea of how to do it! :D Thanks!

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local targets = {Torso = true, HumanoidRootPart = true}
local sel = Instance.new("SelectionBox", player.PlayerGui)

mouse.Move:connect(function()
    if mouse.Target and targets[mouse.Target.Name] then
        sel.Adornee = mouse.Target
    else
        sel.Adornee = nil
    end
end)
0
Don't just post code! Provide detailed explanations! Perci1 4988 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Hello Timster111!

Yes, there is a way to put a selection box over just a part. Just set the Selection Box's Adornee property to the part in question. Your question about putting it over a part hovered over by the mouse is a tad bit trickier, but very doable.

--note that this needs to be in a local script
--define variables
local m = game.Players.LocalPlayer:GetMouse()
local IsBoxUp = false
local BoxedPart = nil

--set an anonymous function to run every time the player moves his mouse
--you can use a while loop if you want it to check constantly, but I find this to be less of a strain
m.Move:connect(function()
    if m.Target then
        if not IsBoxUp then    --make the box
            IsBoxUp = true
            BoxedPart = m.Target
            sb = Instance.new("SelectionBox", m.Target)
            sb.Adornee = m.Target
        elseif IsBoxUp and m.Target ~= BoxedPart then    --destroy the old box and make a new one
            sb:Destroy()
            BoxedPart = m.Target
            sb = Instance.new("SelectionBox", m.Target)
            sb.Adornee = m.Target
        end
    end
end)
0
Use the code the guy above me posted. It's far cleaner. IREaPAR110 5 — 10y
0
I like your explaining so its a hard choice to choose who to pick... Timster111 25 — 10y

Answer this question