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
01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local targets = {Torso = true, HumanoidRootPart = true}
04local sel = Instance.new("SelectionBox", player.PlayerGui)
05 
06mouse.Move:connect(function()
07    if mouse.Target and targets[mouse.Target.Name] then
08        sel.Adornee = mouse.Target
09    else
10        sel.Adornee = nil
11    end
12end)
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.

01--note that this needs to be in a local script
02--define variables
03local m = game.Players.LocalPlayer:GetMouse()
04local IsBoxUp = false
05local BoxedPart = nil
06 
07--set an anonymous function to run every time the player moves his mouse
08--you can use a while loop if you want it to check constantly, but I find this to be less of a strain
09m.Move:connect(function()
10    if m.Target then
11        if not IsBoxUp then    --make the box
12            IsBoxUp = true
13            BoxedPart = m.Target
14            sb = Instance.new("SelectionBox", m.Target)
15            sb.Adornee = m.Target
View all 23 lines...
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