Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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)

1 comment

0

Don't just post code! Provide detailed explanations!

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)

2 comments

0

Use the code the guy above me posted. It's far cleaner.

0

I like your explaining so its a hard choice to choose who to pick...

This discussion is preserved as it was. New answers, comments, and votes are closed.