im trying to give avatar body parts an outline so players can see the exact size of specific bundle body parts (a viewable hitbox, basically) im wanting it to look like this:
(this is me selecting my avatar’s body parts in studio)
i have no idea how to go about doing this, i have looked at gears that do stuff similar [Lightning Wand, Hyperlaser Gun, etc] but im not not sure how to implement the part im wanting from the gear into the experience. i have also tried to find a forum post about this but i couldn’t find what i was looking for.
@TheDCraft is right here is example code using that:
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA('BasePart') and child.Name ~= 'HumanoidRootPart' then
local box = Instance.new('SelectionBox')
box.Color3 = Color3.fromRGB(0, 170, 255)
box.LineThickness = 0.02
box.Adornee = child
box.Parent = child
end
end
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
for _, child in pairs(character:GetChildren()) do
if child:IsA('BasePart') and child.Name ~= 'HumanoidRootPart' then
local box = Instance.new('SelectionBox')
box.Color3 = Color3.fromRGB(0, 170, 255)
box.LineThickness = 0.02
box.Adornee = child
box.Parent = child
end
end
end)
if child:IsA('BasePart') and child.Name ~= 'HumanoidRootPart' then
with this:
if (child:IsA('MeshPart') or child:IsA('BasePart')) and child.Name ~= 'HumanoidRootPart' then
However there is one more problem because you will heave to delay script until mesh part is loaded otherwise selection box won’t spawn. To fix this you could simply place wait(3) before for loop but that’s not the best solution. So i recommend using this code:
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function() --Here we wait until all meshes are loaded
local character = player.Character or player.CharacterAdded:Wait()
for _, child in pairs(character:GetChildren()) do
if (child:IsA('MeshPart') or child:IsA('BasePart')) and child.Name ~= 'HumanoidRootPart' then
local box = Instance.new('SelectionBox')
box.Color3 = Color3.fromRGB(0, 170, 255)
box.LineThickness = 0.02
box.Adornee = child
box.Parent = child
end
end
end)
end)
The ‘BasePart’ class is the base class for all ‘Part’ classes, the ‘MeshPart’, ‘UnionPart’, ‘Part’ and other classes are derived from it, IsA("BasePart") alone should suffice.
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerAdded(Player)
local function OnCharacterAdded(Character)
if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
for _, Child in ipairs(Character:GetChildren()) do
if not (Child:IsA("BasePart")) then continue end
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Adornee = Child
--Set 'SelectionBox' properties here.
SelectionBox.Parent = Child
end
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
Players.PlayerAdded:Connect(OnPlayerAdded)