When players are wearing custom accessories on them, and having two accessories on same bodypart say torso, they end up clipping through each other.
-- Inside TradeableData Module
["Leaf Vest"] = {
Description = "A basic vest that offers sufficient protection.",
Rarity = "Uncommon",
ItemType = "Torso",
HasViewport = true,
AccessoryData = {
{
C0 = CFrame.new(0,0,0, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0,-0.065, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "vest"
},
{
C0 = CFrame.new(0,-1,0.59, 1,0,0, 0,1,0, 0,0,1),
C1 = CFrame.new(0,0.05,0.07, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "white"
},
{
C0 = CFrame.new(0,-0.75,0, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0.05,0.05, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "shoulder"
},
{
C0 = CFrame.new(0,-1.25,0.05, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0.15,0, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "nick"
},
{
C0 = CFrame.new(0,-0.2,-0.705, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0,0.05, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "bag2"
},
{
C0 = CFrame.new(0,-0.2,-0.65, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0,-0.05, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "bag1"
},
{
C0 = CFrame.new(0,0,0.635, -1,0,0, 0,1,0, 0,0,-1),
C1 = CFrame.new(0,0,0, 1,0,0, 0,1,0, 0,0,1),
Part1 = "Torso",
Part0 = "back"
},
},
Stats = {
Health = 10,
Defense = 2,
Chakra = 5,
Stamina = 0,
Speed = 0,
Damage = 0,
MaxHealth = 0,
MaxChakra = 0,
MaxStamina = 0,
Weapon = 1,
Taijutsu = 1
},
},
Inventory Manager Module:
-- Add this constant at the top of InventoryManager
local LAYER_OFFSETS = {
Head = CFrame.new(0, 0.08, 0), -- Move up per layer
Face = CFrame.new(0, 0, 0.05), -- Move forward per layer
Torso = CFrame.new(0, 0, 0.03), -- Move forward per layer
Clothing = CFrame.new(0, 0, 0.04), -- Move forward per layer
Back = CFrame.new(0, 0, -0.05), -- Move backward per layer
Arm = CFrame.new(0.02, 0, 0), -- Move outward per layer
Leg = CFrame.new(0.02, 0, 0), -- Move outward per layer
Shoulder = CFrame.new(0, 0.05, 0), -- Move up per layer
Neck = CFrame.new(0, 0.03, 0), -- Move up per layer
Waist = CFrame.new(0, 0, 0.03), -- Move forward per layer
}
-- Set up physics collision groups
function InventoryManager:SetupCollisionGroups()
-- Create collision groups if they don't exist
local success, message = pcall(function()
PhysicsService:RegisterCollisionGroup(CHARACTER_COLLISION_GROUP)
PhysicsService:RegisterCollisionGroup(ACCESSORY_COLLISION_GROUP)
-- Prevent accessories from colliding with each other
PhysicsService:CollisionGroupSetCollidable(ACCESSORY_COLLISION_GROUP, ACCESSORY_COLLISION_GROUP, true)
-- Allow accessories to interact with the world but not with character parts
PhysicsService:CollisionGroupSetCollidable(ACCESSORY_COLLISION_GROUP, CHARACTER_COLLISION_GROUP, false)
end)
if not success then
warn("[InventoryManager]: Error setting up collision groups:", message)
end
end
-- Initialize accessory layer management and character monitoring
function InventoryManager:InitializeAccessories()
AccessoryLayerManager:Initialize()
local function setupCharacterMonitoring(player, character)
if not character:FindFirstChild("Accessories") then character:WaitForChild("Accessories", 5) end
if character:FindFirstChild("Accessories") then
task.wait(1)
AccessoryLayerManager:RegisterCharacter(character)
-- Set character parts to character collision group
for _, part in pairs(character:GetDescendants()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, CHARACTER_COLLISION_GROUP)
end
end
end
end
local function setupPlayer(player)
player.CharacterAdded:Connect(function(character) setupCharacterMonitoring(player, character) end)
if player.Character then setupCharacterMonitoring(player, player.Character) end
end
Players.PlayerAdded:Connect(setupPlayer)
for _, player in pairs(Players:GetPlayers()) do setupPlayer(player) end
end
-- Ensure folders exist for accessory management
function InventoryManager:EnsureAccessoryFolderExists(folderType)
if not ServerStorage.Assets.Accessories.AccessoryTypes:FindFirstChild(folderType) then
local newFolder = Instance.new("Folder", ServerStorage.Assets.Accessories.AccessoryTypes)
newFolder.Name = folderType
return true
end
return false
end
function InventoryManager:EnsureCharacterAccessoryFolder(character, folderType)
if not character.Accessories:FindFirstChild(folderType) then
local newFolder = Instance.new("Folder", character.Accessories)
newFolder.Name = folderType
return newFolder
end
return character.Accessories[folderType]
end
-- Get accessory asset from appropriate location
function InventoryManager:GetAccessoryAsset(itemType, accessoryName)
InventoryManager:EnsureAccessoryFolderExists(itemType)
if ServerStorage.Assets.Accessories.AccessoryTypes[itemType]:FindFirstChild(accessoryName) then
return ServerStorage.Assets.Accessories.AccessoryTypes[itemType][accessoryName]
end
-- Check alternate locations for specific types
if itemType == "Clothing" and ServerStorage.Assets.Accessories.AccessoryTypes.Clothing:FindFirstChild(accessoryName) then
return ServerStorage.Assets.Accessories.AccessoryTypes.Clothing[accessoryName]
elseif itemType == "Torso" and ServerStorage.Assets.Accessories.AccessoryTypes.Torso:FindFirstChild(accessoryName) then
return ServerStorage.Assets.Accessories.AccessoryTypes.Torso[accessoryName]
end
return nil
end
-- Configure accessory physics and collision properties
function InventoryManager:ConfigureAccessoryPhysics(accessory)
for _, part in pairs(accessory:GetDescendants()) do
if part:IsA("BasePart") then
-- Set common properties for all accessory parts
part.CanCollide = false
part.Massless = true
-- Set collision group
PhysicsService:SetPartCollisionGroup(part, ACCESSORY_COLLISION_GROUP)
end
end
end
-- Apply color customization to accessory
function InventoryManager:ColorAccessory(Accessory, Player, Profile)
if not Profile.ClientData then return end
local WrapsColor = Profile.ClientData.WrapsColor
local HairColor = Profile.ClientData.HairColor
local EyeColor = Profile.ClientData.EyeColor
for _, part in pairs(Accessory:GetChildren()) do
if part:IsA("BasePart") then
if part.Name:lower():match("hair") and HairColor then
part.Color = Color3.fromRGB(HairColor[1], HairColor[2], HairColor[3])
elseif part.Name:lower():match("eye") and EyeColor then
part.Color = Color3.fromRGB(EyeColor[1], EyeColor[2], EyeColor[3])
elseif part.Name:lower():match("wrap") and WrapsColor then
part.Color = Color3.fromRGB(WrapsColor[1], WrapsColor[2], WrapsColor[3])
end
end
end
end
-- Cleanup player accessory data
function InventoryManager:CleanupAccessoryData(PlayerName)
if AccessoryData[PlayerName] then
for i in pairs(AccessoryData[PlayerName]) do AccessoryData[PlayerName][i] = nil end
AccessoryData[PlayerName] = nil
end
end
-- Get valid slots for an item
function InventoryManager:GetValidSlotTypes(itemName)
if not TradeablesData[itemName] then return {} end
return {TradeablesData[itemName].ItemType}
end
-- Check if item can equip to slot
function InventoryManager:CanEquipToSlot(itemName, slotType)
local validSlots = InventoryManager:GetValidSlotTypes(itemName)
for _, validType in ipairs(validSlots) do
if validType == slotType then return true end
end
return false
end
-- Fixed EquipItem function to ensure proper sync
function InventoryManager:EquipItem(Player, AccessoryName, SpecificSlot)
local Profile = DataManager:RequestProfile(Player)
if not Profile or not TradeablesData[AccessoryName] then return false end
-- Get item type and determine target slot
local BaseItemType = TradeablesData[AccessoryName].ItemType
local TargetSlot = SpecificSlot or BaseItemType
-- Check if item can be equipped to slot
if not InventoryManager:CanEquipToSlot(AccessoryName, TargetSlot) then
ReplicatedStorage.Remotes.AccessoryEquipFailed:FireClient(Player, AccessoryName, "This item cannot be equipped in this slot.")
return false
end
-- Update data model
local SuccessfulEquip = DataManager:ModifyEquippedAccessories(Player, TargetSlot, AccessoryName)
if SuccessfulEquip ~= "EquipSuccess" then return false end
local Character = Player.Character
if not Character then return false end
-- Clear slot and get accessory asset
local SlotFolder = InventoryManager:EnsureCharacterAccessoryFolder(Character, TargetSlot)
SlotFolder:ClearAllChildren()
local AccessoryAsset = InventoryManager:GetAccessoryAsset(BaseItemType, AccessoryName)
if not AccessoryAsset then return false end
-- Clone and prepare accessory
local Accessory = AccessoryAsset:Clone()
InventoryManager:ColorAccessory(Accessory, Player, Profile)
Accessory.Parent = SlotFolder
-- Create welds
local DataAccessory = TradeablesData[AccessoryName]
for _, AccessoryData in ipairs(DataAccessory.AccessoryData) do
local AccessoryPart = AccessoryData.Part0
local BodyPart = Character[AccessoryData.Part1]
if not BodyPart then continue end
local Weld = Instance.new("Weld")
Weld.Part1 = BodyPart
Weld.C0 = AccessoryData.C0
if AccessoryData.C1 then Weld.C1 = AccessoryData.C1 end
if AccessoryPart == "self" then
Weld.Part0 = Accessory
Weld.Parent = Accessory
else
if not Accessory:FindFirstChild(AccessoryPart) then continue end
Weld.Part0 = Accessory[AccessoryPart]
Weld.Parent = Accessory[AccessoryPart]
end
end
-- Apply special effects
if DataAccessory.HideName then
Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end
if DataAccessory.HideHair then
for _, Child in ipairs(Character:GetChildren()) do
if Child.ClassName == "Accessory" then
if Child.Handle:FindFirstChild("AccessoryWeld") then Child.Handle.AccessoryWeld:Destroy() end
if not ServerStorage.LiveAssets:FindFirstChild(Character.Name) then
local folder = Instance.new("Folder")
folder.Name = Character.Name
folder.Parent = ServerStorage.LiveAssets
end
Child.Parent = ServerStorage.LiveAssets[Character.Name]
end
end
end
-- FIXED: Only call RecalculateAllAttributes - removed the duplicate direct SetAttribute calls
InventoryManager:RecalculateAllAttributes(Player, Profile, true) -- Fill to max when equipping items
-- Create preview and notify client
ReplicatedStorage.Remotes.UpdateAccessoryEquipButton:FireClient(Player, AccessoryName)
ReplicatedStorage.Remotes.AccessoryEquipSuccess:FireClient(Player, AccessoryName, TargetSlot)
-- Ensure inventory is synchronized after equipping with delay to prevent race conditions
task.spawn(function()
task.wait(0.1)
InventoryManager:SyncClientInventory(Player, Profile)
end)
return true
end