function FRAMEWORK:GetLastUsedWeapon(weap_NEW)
    local weap_LAST = FRAMEWORK.inv_CURRENT[#FRAMEWORK.inv_CURRENT] -- Get the last weapon used
    local weap_BEFORE_LAST = FRAMEWORK.inv_CURRENT[#FRAMEWORK.inv_CURRENT - 1] -- Get the weapon used before the last one

    if weap_NEW == 1 then -- If the player pressed 1
        if weap_LAST == FRAMEWORK.inv_DEFAULT[1] then -- If the last weapon was the primary
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[2] -- Set the current weapon to the secondary
        else
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[1] -- Set the current weapon to the primary
        end
    elseif weap_NEW == 2 then -- If the player pressed 2
        if weap_LAST == FRAMEWORK.inv_DEFAULT[2] then -- If the last weapon was the secondary
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[1] -- Set the current weapon to the primary
        else
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[2] -- Set the current weapon to the secondary
        end
    elseif weap_NEW == 3 then -- If the player pressed 3
        if weap_LAST == FRAMEWORK.inv_DEFAULT[3] then -- If the last weapon was the melee
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[1] -- Set the current weapon to the primary
        else
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[3] -- Set the current weapon to the melee
        end
    elseif UserInputService:IsKeyDown(Enum.KeyCode.Q) then -- If the player pressed Q
        if weap_BEFORE_LAST == FRAMEWORK.inv_DEFAULT[1] then -- If the weapon before the last was the primary
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[2] -- Set the current weapon to the secondary
        elseif weap_BEFORE_LAST == FRAMEWORK.inv_DEFAULT[2] then -- If the weapon before the last was the secondary
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[3] -- Set the current weapon to the melee
        else
            FRAMEWORK.cur_WEAPON = FRAMEWORK.inv_DEFAULT[1] -- Set the current weapon to the primary
        end
    end
end

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: