Get every attachment that a player has on one of their weapons?

Hey, does anyone know how I can get all the attachments that a player has on one of their weapons in LUA?

Try my script I made a while back.
Link
It gives all the weapons, ammo and attachments. I just didn’t include the gun skins

1 Like
-- Set the player to get the weapon attachments for
local targetPlayer = PlayerId()

Citizen.CreateThread(function()
    -- Wait for the player to join the server
    while not NetworkIsPlayerActive(targetPlayer) do
        Citizen.Wait(0)
    end

    -- Get the player's ped
    local playerPed = GetPlayerPed(targetPlayer)

    -- Check if the player has a weapon
    if HasPedGotWeapon(playerPed, GetSelectedPedWeapon(playerPed), false) then
        -- Get the weapon the player is holding
        local weapon = GetSelectedPedWeapon(playerPed)

        -- Get the number of attachments on the weapon
        local numAttachments = GetNumWeaponAttachments(weapon)

        -- Print a message indicating the number of attachments on the weapon
        print("Player has " .. numAttachments .. " attachments on their weapon")

        -- Loop through each attachment on the weapon
        for i = 1, numAttachments do
            -- Get the attachment at the current index
            local attachment = GetWeaponAttachment(weapon, i)

            -- Print the name of the attachment
            print("Attachment " .. i .. ": " .. attachment.name)