#Player Accessory ID Deletion

4 messages · Page 1 of 1 (latest)

runic jasper
#

Hi, how can i delete an accessory from a player if its a certain id/name. I tried many aproaches but i dont know how to figure it out. For example i even tried waiting for the player in workspace and deleting the accessory object by name (Accessory (MeshPartAccessory)), but it didnt work too, or i just did it wrong. Does anyone know how to do this?

valid rampart
#

Place this script inside a StarterPlayerScripts or a StarterCharacterScripts to ensure it runs on the player's client.

local function removeAccessoryByName(accessoryName)
    -- Get the local player
    local player = game.Players.LocalPlayer
    
    -- Wait until the player's character is loaded
    local character = player.Character or player.CharacterAdded:Wait()
    
    -- Ensure the character has an Accessories folder
    local accessoriesFolder = character:FindFirstChild("Accessories")
    
    if not accessoriesFolder then
        -- If no Accessories folder exists, create one
        accessoriesFolder = Instance.new("Folder")
        accessoriesFolder.Name = "Accessories"
        accessoriesFolder.Parent = character
    end
    
    -- Iterate through each accessory in the folder
    for _, accessory in pairs(accessoriesFolder:GetChildren()) do
        -- Check if the accessory matches the specified name
        if accessory.Name == accessoryName then
            accessory:Destroy()  -- Remove the accessory
            print("Removed accessory: " .. accessoryName)
            return  -- Exit after removing the accessory
        end
    end
    
    print("Accessory not found: " .. accessoryName)
end

-- Example usage: replace "Hat" with the name of the accessory you want to remove
removeAccessoryByName("Hat")
runic jasper
obsidian trailBOT
#

studio** You are now Level 1! **studio